#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
int t;
int n;
int main() {
cin >> t;
while (t--) {
cin >> n;
int p = n;
for (int i = 2; i * i <= n; ++i)
if (n % i == 0) p = min (p, i);
if (p == n) cout << "Prime\n";
else cout << p << endl;
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
int t;
double x, y;
char c;
int main() {
cin >> t;
while (t--) {
cin >> x >> c >> y;
if (c == '+') {
x += y;
printf("%.2f\n", x);
} else if (c == '-') {
x -= y;
printf("%.2f\n", x);
} else if (c == '*') {
x *= y;
printf("%.2f\n", x);
} else {
if (y == 0) cout << "NaN\n";
else printf("%.2f\n", x / y);
}
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int factor(int n){
int a;
if(n%2==0)return 2;
for(a=3;a*a<=n;a++){
if(n%a==0)return a;
}
return n;
}
bool prime(int n){
if(n<2)return false;
if(n<=3)return true;
if(!(n%2) || !(n%3))return false;
for(int i=5;i*i<=n;i+=6){
if(!(n%i) || !(n%(i+2))) return false;
}
return true;
}
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
if(prime(n))
cout<<"Prime"<<endl;
else
cout<<factor(n)<<endl;
}
}
a=list(map(int,input().split()))
diff=int(input())
pair=[]
for i,j in zip(a,a[1:]):
if j-i==diff:
pair.append([i,j])
if pair!=[]:
print("Pair Found: ",end="")
n=len(pair)
for i in range(n):
print("(",pair[i][0],",",pair[i][1],")",end="",sep="")
if i!=n-1:
print(",",end="")
else:
print("No Pair Found")
#include<iostream>
using namespace std;
int main()
{
int n;
cin >> n;
for(int x = 0; x < n; x++)
{
int num;
cin >> num;
bool prime = true;
if(num == 2)
prime = true;
else
{
for(int b = 2; b < num; b++)
if((num % b) == 0)
prime = false;
}
if(prime == true)
cout << "Prime" << endl;
else
{
for(int c = 2; c < num; c++)
{
if((num % c) == 0)
{
cout << c << endl;
c = c + 99999;
}
}
}
}
}
n = int(input())
for i in range(n):
a, o, b = input().split(" ")
a, b = float(a), float(b)
try:
if o == "+":
c = a+b
elif o == "-":
c = a-b
elif o == "*":
c = a*b
elif o == "/":
c = a/b
print("%.2f" % c)
except Exception:
print("NaN")
#include <iostream>
using namespace std;
int main()
{
int T;
cin>>T;
float a,b,ans;
char o;
while(T != 0)
{
cin>>a>>o>>b;
if (o == '+')
{
ans = a+b;
cout<<ans<<endl;
}
else if (o == '-')
{
ans = a-b;
cout<<ans<<endl;
}
else if (o == '*')
{
ans = a*b;
cout<<ans<<endl;
}
else if (o == '/')
{
ans = a-b;
cout<<ans<<endl;
}
else
{
cout<<"NaN"<<endl;
}
T--;
}
}
import java.util.*;
import java.io.*;
class Main {
public static void main(String[] args) throws Exception {
int[] arr = new int[1001];
arr[0] = 0;
arr[1] = 2;
arr[2] = 3;
for(int i=3; i< arr.length; i++){
arr[i] = arr[i-1] + arr[i-2];
}
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int cases = Integer.parseInt(br.readLine());
for(int i=0; i<cases; i++){
int num = Integer.parseInt(br.readLine());
System.out.println(arr[num]);
}
}
}
#include<iostream>
using namespace std;
int main()
{
int test;
cin>>test;
for(int i=0;i<test;i++)
{
int prime;
cin>>prime;
bool p=true;
int small = 0;
for(int c=2;c<prime;c++)
{
if(prime%c==0)
{
p=false;
small=c;
break;
}
}
if(p)
cout<<"prime"<<endl;
else
cout<<small<<endl;
}
return 0;
}
a=list(map(int,input().split()))
diff=int(input())
pair=[]
for i,j in zip(a,a[1:]):
if j-i==diff:
pair.append([i,j])
if pair!=[]:
print("Pair Found: ",end="")
n=len(pair)
for i in range(n):
print("(",pair[i][0],",",pair[i][1],")",end="",sep="")
if i!=n-1:
print(", ",end="")
else:
print("No Pair Found")
#include<bits/stdc++.h>
#include <iomanip>
using namespace std;
int main()
{
int T;
float A, B;
char O;
cin>>T;
for (int i = 0; i < T; i++)
{
cin>>O;
cin>>A;
cin>>B;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
if (O == '+')
cout<<(A + B);
else if (O == '-')
cout<<(A - B);
else if (O == '*')
cout<<(A * B);
else if (O == '/')
cout<<(A / B);
else
cout<<"NaN";
}
return 0;
}
import java.util.*;
import java.io.*;
class Main {
public static void main(String[] args) throws Exception {
long[] arr = new long[1001];
arr[0] = 0;
arr[1] = 2;
arr[2] = 3;
for(int i=3; i< arr.length; i++){
arr[i] = arr[i-1] + arr[i-2];
}
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int cases = Integer.parseInt(br.readLine());
for(int i=0; i<cases; i++){
int num = Integer.parseInt(br.readLine());
System.out.println(arr[num]);
}
}
}
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
int t;
vector<int> v;
int main() {
while (cin >> t) {
v.push_back(t);
}
while (sz(v) > 1) {
vector<int> tmp;
for (int i = 0; i < sz(v) - 1; ++i)
tmp.push_back(abs(v[i] - v[i + 1]));
swap(v, tmp);
for (int i = 0; i < sz(v); ++i)
printf("%d%c", v[i], " \n"[i==sz(v)-1]);
//cout << endl;
}
//cout << v[0] << endl;
return 0;
}
a=list(map(int,input().split()))
diff=int(input())
pair=[]
for i,j in zip(a,a[1:]):
if j-i==diff:
pair.append([i,j])
if pair!=[]:
print("Pair Found: ",end="")
n=len(pair)
pair=sorted(pair)
for i in range(n):
print("(",pair[i][0],",",pair[i][1],")",end="",sep="")
if i!=n-1:
print(", ",end="")
else:
print("No Pair Found")
//package prosolve_im26c4u;
import java.util.*;
import java.io.*;
import java.util.regex.Pattern;
public class Main {
// public static void main(String[] args) throws IOException{
// BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// int numCases = Integer.parseInt(br.readLine());
//
// for(int i=0; i< numCases; i++){
// TreeMap<String, Integer> map = new TreeMap<>();
// int numWords = Integer.parseInt(br.readLine());
// for(int j=0; j<numWords; j++){
// String[] a = br.readLine().split("\t");
// if(!map.containsKey(a[0])){
// map.put(a[0], 0);
// }
// map.put(a[0], map.get(a[0])+1);
// }
//
// for(Map.Entry<String, Integer> m : map.entrySet()){
// System.out.println(m.getValue()+"\t"+m.getKey());
//
// }
// if(i!=numCases-1) System.out.println("");
// }
// }
// public static void main(String arg[])throws IOException{
// BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// String s = br.readLine();
// String ans = s.replaceAll("[^A-Za-z]","");
// System.out.println(ans);
// }
public static boolean composite[] = new boolean[10001];
public static int primeF[] = new int[10001];
public static void soe(int up){
int sqrt = (int)Math.sqrt(up);
for(int i=2;i<=sqrt;i++){
if(!composite[i]){
for(int j=i*i;j<=up;j+=i){
// System.out.println(j);
composite[j] = true;
if(primeF[j]==0){
primeF[j] = i;
// System.out.println(primeF[j]);
}else{
primeF[j] = Math.min(i,primeF[j]);
}
}
}
}
}
public static void main (String args[]) throws IOException{
String input = "a.in";
String output = "a.out";
boolean file = false;
BufferedReader br;
if(file)
br = new BufferedReader(new FileReader(input));
else
br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pr;
if(file){
pr = new PrintWriter(new FileWriter(output));
}else{
pr = new PrintWriter(System.out);
}
soe(10000);
int T = Integer.parseInt(br.readLine());
for(int i=0;i<T;i++){
int N = Integer.parseInt(br.readLine());
if(primeF[N]==0){
System.out.println("Prime");
}else{
System.out.println(primeF[N]);
}
}
pr.close();
}
}
import java.util.*;
import java.io.*;
import java.math.BigInteger;
class Main {
public static void main(String[] args) throws Exception {
BigInteger[] arr = new BigInteger[1001];
arr[0] = new BigInteger("0");
arr[1] = new BigInteger("2");
arr[2] = new BigInteger("3");
for(int i=3; i< arr.length; i++){
arr[i] = arr[i-1].add(arr[i-2]);
}
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int cases = Integer.parseInt(br.readLine());
for(int i=0; i<cases; i++){
int num = Integer.parseInt(br.readLine());
System.out.println(arr[num]);
}
}
}
#include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
double x,y;
char ch;
cin>>x>>ch>>y;
if(ch=='+'){
printf("%.2f\n",x+y );
}
else if (ch=='-'){
printf("%.2f\n",x-y );
}
else if(ch =='*'){
printf("%.2f\n",x*y );
}
else if(ch =='/'){
if(y==0)
cout<<"NaN"<<endl;
else
printf("%.2f\n",x/y );
}
}
}
#include<bits/stdc++.h>
#include <iomanip>
using namespace std;
int main()
{
int T;
float A, B;
char O;
cin>>T;
for (int i = 0; i < T; i++)
{
cin>>A>>O>>B;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
if (O == '+')
cout<<(A + B);
else if (O == '-')
cout<<(A - B);
else if (O == '*')
cout<<(A * B);
else if (O == '/')
cout<<(A / B);
else
cout<<"NaN";
}
return 0;
}
x = list(map(int, input().split(' ')))
y = int(input())
z = [y + i for i in x]
p = []
for k in z:
if k in x:
p.append([k - y, k])
if len(p) == 0:
print("No Pair Found")
else:
print("Pair Found: " + ", ".join(["(%d, %d)" % (a, b) for a, b in p]))
#include<iostream>
#include <iomanip>
using namespace std;
int main(){
int T;
cin >> T;
float f1,f2;
char c;
for(int i=0;i<T;i++){
cin >> f1 >> c >> f2;
if(c == '-'){
f1 -=f2;
}
else if(c == '+'){
f1 +=f2;
}
else if(c == '*'){
f1 *=f2;
}
else if(c == '/'){
f1 /=f2;
}
cout << fixed << setprecision(2) << f1 << endl;
}
}
string = input()
num = string.split(' ')
k = len(num)
while k != 1:
for i in range(k-1):
d = int(num[i]) - int(num [i+1])
d = abs(d)
num[i] = d
print(str(d) + " ",end='')
k = k - 1
print()
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class F {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int T = Integer.parseInt(br.readLine());
while(T>0){
StringTokenizer st = new StringTokenizer(br.readLine());
double a = Double.parseDouble(st.nextToken());
char o = st.nextToken().charAt(0);
double b = Double.parseDouble(st.nextToken());
switch (o){
case '+':
sb.append(String.format("%.2f",a+b));
break;
case '-':
sb.append(String.format("%.2f",a-b));
break;
case '*':
sb.append(String.format("%.2f",a*b));
break;
case '/':
if(b==0){
sb.append("NaN");
}
else {
sb.append(String.format("%.2f", a / b));
}
break;
}
sb.append("\n");
T--;
}
System.out.println(sb.toString());
}
}
t=int(input())
for _ in range(t):
try:
print("{:.2f}".format(eval(input())))
except:
print("NaN")
x = list(map(int, input().strip().split(' ')))
y = int(input())
z = [y + i for i in x]
p = []
for k in z:
if k in x:
p.append([k - y, k])
if len(p) == 0:
print("No Pair Found")
else:
print("Pair Found: " + ", ".join(["(%d, %d)" % (a, b) for a, b in p]))
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int n = 0;
cin >> n;
cout << fixed << showpoint << setprecision(2);
for(int t = 0; t < n; t++)
{
float x, y;
char z;
cin >> x >> z >> y;
if(z == '+')
cout << x + y << endl;
else if(z == '-')
cout << x - y << endl;
else if(z == '*')
cout << x * y << endl;
else if(z == '/')
{
if(y == 0)
cout << "NaN" << endl;
else
cout << x / y << endl;
}
}
}
#include<bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sf(x) scanf("%d\n", &x)
#define pf(x) printf("%d\n", &x)
#define all(x) x.begin(), x.end
#define fill(a,x)memset(a,x,sizeof a)
#define size_a(a)sizeof(a) / sizeof(a[0])
#define dbg(x) cerr <<(#x) << "is" <<x<<'\n'
#define repi(i,a,n) for (int i = (int)a;i<(int)n;++i)
#define repll(i,a,n) for (int i = (ll)a;i<(ll)n;++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef vector<ii>vii;
typedef vector<int>vi;
// Global Variable Declaration
float a,b;
char o;
int T;
int main(){
cin >>T;
while(T--){
cin >> a >> o >> b;
if(o=='+')
cout<<fixed<<setprecision(2)<<(float)a+b<<endl;
else if(o=='-')
cout<<fixed<<setprecision(2)<<(float)a-b<<endl;
else if(o=='*')
cout<<fixed<<setprecision(2)<<(float)a*b<<endl;
else
cout<<fixed<<setprecision(2)<<(float)a/b<<endl;
}
return 0;
}
nums = [int(x) for x in input().split()]
diff = int(input())
list1 = []
for i in nums:
for k in nums:
if(i < k):
if( abs(i-k) is diff):
list1.append((i,k))
if(len(list1) > 0):
output = ""
for i in list1:
output += ",({},{})".format(i[0],i[1])
print("Pair Found: {}".format(output[1:]))
else:
print("No Pair Found")
import java.util.Scanner;
public class I
{
public static void main(String []args){
Scanner input = new Scanner(System.in);
int cases = input.nextInt();
for(int x=0; x<cases; x++){
int n = input.nextInt();
int count = 0;
int firstNum = 1;
if(n == 1)
System.out.println("Prime");
else{
for(int y=2; y<=n; y++){
if(n%y==0){
if(firstNum==1)
firstNum=y;
count++;
}
if(count>1){
System.out.println(firstNum);
break;
}
}
}
if(count==1)
System.out.println("Prime");
}
}
}
num = input()
data = []
for i in range(0, int(num)):
req = str(input())
data.append(req)
#print(data)
for ii in range(0, len(data)):
A=data[ii].split()[0]
O=data[ii].split()[1]
B=data[ii].split()[2]
if O=="+":
print(float(A)+float(B))
elif O=="-":
print(float(A)-float(B))
elif O=="*":
print(float(A)*float(B))
else:
print(float(A)/float(B))
x = list(map(int, input().strip().split(' ')))
while True:
d = []
for a, b in zip(x[1:], x[:-1]):
d.append(abs(a - b))
print(' '.join(list(map(str, d))))
if len(d) == 1:
break
x = d[:]
nums = [int(x) for x in input().split()]
diff = int(input())
list1 = []
for i in nums:
for k in nums:
if(i < k):
if( abs(i-k) is diff):
list1.append((i,k))
if(len(list1) > 0):
output = ""
for i in list1:
output += ", ({}, {})".format(i[0],i[1])
print("Pair Found: {}".format(output[2:]))
else:
print("No Pair Found")
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int num[6];
for(int i=0;i<6;i++)
{
cin>>num[i];
}
int a,b;
/*
counter=6;
while(count>0)
{
a = num[1];
}
*/
for(int j=5;j>0;j--)
{
for(int d=0;d<j;d++)
{
num[d]=abs(num[d+1]-num[d]);
cout<<num[d]<<" ";
}
cout<<endl;
}
return 0;
}
def predict(x, beta, alpha):
return alpha + beta * x
n = int(input())
xs = []
ys = []
for ni in range(n):
inx, iny = [float(c) for c in input().split(' ')]
xs.append(inx)
ys.append(iny)
meanx = sum(xs) / len(xs)
meany = sum(ys) / len(ys)
# train
top = []
bottom = []
for ni in range(n):
tans = (xs[ni] - meanx) * (ys[ni] - meany)
top.append(tans)
bans = (xs[ni] - meanx) ** 2
bottom.append(bans)
beta = sum(top) / sum(bottom)
alpha = meany - beta * meanx
print('{:.4f} {:.4f}'.format(beta, alpha))
nx = int(input())
for xi in range(nx):
x = float(input())
predy = predict(x, beta, alpha)
print('{:.4f}'.format(predy))
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double days, mgarb, garb[1000];
double tot = 0;
cin >> days >> mgarb;
for(int i = 0; i < days; i++)
{
cin >> garb[i];
}
for (int i = 0; i < days; i++)
{
tot += garb[i];
}
cout << ceil(tot/mgarb);
}
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int n = 0;
cin >> n;
cout << fixed << showpoint << setprecision(2);
for(int t = 0; t < n; t++)
{
float x, y;
char z;
cin >> x >> z >> y;
if(z == '+')
cout << x + y << endl;
else if(z == '-')
cout << x - y << endl;
else if(z == '*')
cout << x * y << endl;
else if(z == '/')
{
if(y == 0)
cout << "NaN" << endl;
else
cout << x / y << endl;
}
}
}
#include <iostream>
#include <cstdio>
using namespace std;
int main() {
int n;
double a,b;
char op;
cin>> n;
while(n--){
cin>>a>>op>>b;
switch(op){
case '+':
printf("%.2f\n", a+b);
break;
case '-':
printf("%.2f\n", a-b);
break;
case '*':
printf("%.2f\n", a*b);
break;
case '/':
if(b!=0)
printf("%.2f\n", a/b);
else
printf("NaN\n");
break;
}
}
return 0;
}
#include<bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sf(x) scanf("%d\n", &x)
#define pf(x) printf("%d\n", &x)
#define all(x) x.begin(), x.end
#define fill(a,x)memset(a,x,sizeof a)
#define size_a(a)sizeof(a) / sizeof(a[0])
#define dbg(x) cerr <<(#x) << "is" <<x<<'\n'
#define repi(i,a,n) for (int i = (int)a;i<(int)n;++i)
#define repll(i,a,n) for (int i = (ll)a;i<(ll)n;++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef vector<ii>vii;
typedef vector<int>vi;
// Global Variable Declaration
float a,b;
char o;
int T;
int main(){
cin >>T;
while(T--){
cin >> a >> o >> b;
if(o=='+')
cout<<fixed<<setprecision(2)<<(float)a+b<<endl;
else if(o=='-')
cout<<fixed<<setprecision(2)<<(float)a-b<<endl;
else if(o=='*')
cout<<fixed<<setprecision(2)<<(float)a*b<<endl;
else if(o=='/')
cout<<fixed<<setprecision(2)<<(float)a/b<<endl;
else
cout<<"NaN"<<endl;
}
return 0;
}
a=list(map(int,input().split()))
while len(a)>1:
new_a=[]
for i,j in zip(a,a[1:]):
res=abs(i-j)
new_a.append(res)
print(res,end=" ")
a=new_a[:]
print()
import java.util.*;
import java.io.*;
import java.math.BigInteger;
class Main {
public static void main(String[] args) throws Exception {
int[] arr = new int[10001];
for(int i=2; i< arr.length; i++){
arr[i] = checkPrime(i);
}
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int cases = Integer.parseInt(br.readLine());
for(int i=0; i<cases; i++){
int num = Integer.parseInt(br.readLine());
if(arr[num] == 0) System.out.println("Prime");
else System.out.println(arr[num]);
}
}
public static int checkPrime(int n){
if(n == 2 || n == 3) return 0;
int i =2;
for(; i<=Math.sqrt(n);i++){
if(n%i==0) return i;
}
return 0;
}
}
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
int t;
vector<int> v;
int main() {
while (cin >> t) {
v.push_back(t);
}
int dif = v.back();
v.pop_back();
sort(all(v));
vector<pair<int, int> > ans;
for (int i = 0; i < sz(v); ++i)
for (int j = i + 1; j < sz(v); ++j) {
if (v[j] - v[i] == dif)
ans .push_back(make_pair(v[i], v[j]));
}
if (sz(ans) == 0) {
cout << "No Pair Found\n";
return 0;
}
cout << "Pair Found: (" << ans[0].F << ", " << ans[0].S << ")";
for (int i = 1; i < sz(ans); ++i) {
cout << ", (" << ans[i].F << ", " << ans[i].S <<")";
}
cout << endl;
return 0;
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class G {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
StringTokenizer st = new StringTokenizer(br.readLine());
ArrayList<Integer> arr = new ArrayList<>();
while(st.hasMoreTokens()){
arr.add(Integer.parseInt(st.nextToken()));
}
while(arr.size()!=1) {
ArrayList<Integer> tmp = new ArrayList<>();
for (int j = 0; j < arr.size() - 1; j++) {
tmp.add(Math.abs(arr.get(j) - arr.get(j+1)));
}
arr = new ArrayList<>(tmp);
boolean first = true;
for(Integer i : arr){
if (first) {
sb.append(i);
first = false;
}
else{
sb.append(" "+i);
}
}
sb.append("\n");
}
System.out.println(sb.toString());
}
}
#include<bits/stdc++.h>
#include <iomanip>
using namespace std;
int main()
{
int T;
float A, B;
char O;
cin>>T;
for (int i = 0; i < T; i++)
{
cin>>A>>O>>B;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
if (O == '+')
cout<<(A + B);
else if (O == '-')
cout<<(A - B);
else if (O == '*')
cout<<(A * B);
else if (O == '/')
{
if (B == 0)
cout<<"NaN";
else
cout<<(A / B);
}
}
return 0;
}
#include<iostream>
using namespace std;
bool isPrime(int n){
bool check = true;
for(int i=2; i<n;i++){
if(n%i == 0 || n<2){
check = false;
}
if( n == 2){
check = true;
}
}
return check;
}
int main(){
int T;
cin >> T;
int num;
for(int i=0; i<T;i++){
cin >> num;
if (isPrime(num)){
cout << "Prime" << endl;
}
else
{
for(int j=2;j<num;j++){
if(isPrime(j)){
if(num%j == 0){
cout<< j << endl;
break;
}
}
}
}
}
}
#include<iostream>
#include<vector>
using namespace std;
int main(){
int testcase;
cin>>testcase;
cin.ignore();
for(int i = 0; i < testcase; i++){
int n;
vector<int> v1;
cin>>n;
cin.ignore();
int n_factors = 0;
bool is_prime = true;
for(int j = 2; j <= n; j++ ){
//cout<<j<<endl;
//cout<<"----"<<endl;
//cout<<n_factors<<endl;
if(n % j == 0){
v1.push_back(j);
n_factors = n_factors + 1;
}
if(n_factors > 1){
is_prime = false;
break;
}
}
if(is_prime){
cout<<"Prime"<<endl;
}else{
cout<<v1[0]<<endl;
}
}
}
def generate_new(t):
newt = []
for i in range(len(t)-1):
curr, next = t[i], t[i+1]
dist = abs(curr - next)
newt.append(dist)
s = ' '.join([str(x) for x in newt])
print(s)
return newt
t = [int(x) for x in input().split(' ')]
n = len(t) - 1
for i in range(n):
t = generate_new(t)
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int test;
cin>>test;
for(int i=0;i<test;i++)
{
float a,b;
char sign;
cin>>a>>sign>>b;
if(sign=='+')
cout<<fixed<<setprecision(2)<<a+b<<endl;
if(sign=='-')
cout<<fixed<<setprecision(2)<<a-b<<endl;
if(sign=='*')
cout<<fixed<<setprecision(2)<<a*b<<endl;
if(sign=='/')
cout<<fixed<<setprecision(2)<<a/b<<endl;
}
return 0;
}
#include<iostream>
#include <iomanip>
using namespace std;
int main(){
int T;
cin >> T;
float f1,f2;
char c;
for(int i=0;i<T;i++){
cin >> f1 >> c >> f2;
if(c == '-'){
f1 -=f2;
}
else if(c == '+'){
f1 +=f2;
}
else if(c == '*'){
f1 *=f2;
}
else if(c == '/'){
f1 /=f2;
}
cout << fixed << setprecision(2) << f1 << " ";
}
}
#include<bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sf(x) scanf("%d\n", &x)
#define pf(x) printf("%d\n", &x)
#define all(x) x.begin(), x.end
#define fill(a,x)memset(a,x,sizeof a)
#define size_a(a)sizeof(a) / sizeof(a[0])
#define dbg(x) cerr <<(#x) << "is" <<x<<'\n'
#define repi(i,a,n) for (int i = (int)a;i<(int)n;++i)
#define repll(i,a,n) for (int i = (ll)a;i<(ll)n;++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef vector<ii>vii;
typedef vector<int>vi;
// Global Variable Declaration
double a,b;
char o;
int T;
int main(){
cin >>T;
while(T--){
cin >> a >> o >> b;
if(o=='+')
cout<<fixed<<setprecision(2)<<(double)(a+b)<<endl;
else if(o=='-')
cout<<fixed<<setprecision(2)<<(double)(a-b)<<endl;
else if(o=='*')
cout<<fixed<<setprecision(2)<<(double)(a*b)<<endl;
else if(o=='/')
cout<<fixed<<setprecision(2)<<(double)(a/b)<<endl;
else
cout<<"NaN"<<endl;
}
return 0;
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class C {
static int[] cache = new int[1001];
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int T = Integer.parseInt(br.readLine());
cache[0] = 0;
cache[1] = 2;
cache[2] = 3;
while(T>0){
sb.append(solve(Integer.parseInt(br.readLine())));
sb.append("\n");
T--;
}
System.out.println(sb.toString());
}
public static int solve(int N){
if(cache[N]!=0){
return cache[N];
}
else{
return solve(N-1)+solve(N-2);
}
}
}
#include<bits/stdc++.h>
#include <iomanip>
using namespace std;
int main()
{
int T;
float A, B;
char O;
cin>>T;
for (int i = 0; i < T; i++)
{
cin>>A>>O>>B;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
if (O == '+')
cout<<(A + B);
else if (O == '-')
cout<<(A - B);
else if (O == '*')
cout<<(A * B);
else if (O == '/')
{
if (B == 0)
cout<<"NaN";
else
cout<<(A / B);
}
else
cout<<"NaN";
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
int t;
vector<int> v;
int main() {
while (cin >> t) {
v.push_back(t);
}
int dif = v.back();
v.pop_back();
//sort(all(v));
vector<pair<int, int> > ans;
for (int i = 0; i < sz(v); ++i)
for (int j = i + 1; j < sz(v); ++j) {
if (v[j] - v[i] == dif)
ans .push_back(make_pair(v[i], v[j]));
}
if (sz(ans) == 0) {
cout << "No Pair Found\n";
return 0;
}
if (ans[0].F > ans[0].S) swap(ans[0].F, ans[0].S);
cout << "Pair Found: (" << ans[0].F << ", " << ans[0].S << ")";
for (int i = 1; i < sz(ans); ++i) {
if (ans[i].F > ans[i].S) swap(ans[0].F, ans[0].S);
cout << ", (" << ans[i].F << ", " << ans[i].S <<")";
}
cout << endl;
return 0;
}
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] inputs = br.readLine().split(" ");
int d = Integer.parseInt(br.readLine());
int[] n = new int[inputs.length];
for (int j = 0; j < inputs.length; j++) {
n[j] = Integer.parseInt(inputs[j]);
}
Arrays.sort(n);
List<Integer> index = new ArrayList<>();
for (int j = 0; j < n.length - 1; j++) {
for (int i = j + 1; i < n.length; i++) {
if (n[i] > n[j] + d) {
break;
} else if (n[j] + d == n[i]) {
index.add(j);
index.add(i);
}
}
}
if (!index.isEmpty()) {
System.out.print("Pair found: ");
for (int j = 0; j < index.size(); j += 2) {
System.out.printf("(%d,%d)", n[index.get(j)], n[index.get(j+1)]);
if (j != index.size() - 2) {
System.out.print(", ");
}
}
} else {
System.out.println("No Pair Found");
}
}
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
int T;
cin>>T;
if (T % 2 != 0)
cout<<"Prime";
else
for (int i = 2; i < T; i++)
{
if (T % i != 2)
{
cout<<i;
break;
}
}
return 0;
}
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int num[6];
for(int i=0;i<6;i++)
{
cin>>num[i];
}
int a,b;
/*
counter=6;
while(count>0)
{
a = num[1];
}
*/
for(int j=5;j>0;j--)
{
for(int d=0;d<j;d++)
{
num[d]=abs(num[d+1]-num[d]);
cout<<num[d]<<" ";
}
if(j!=1)
cout<<endl;
}
return 0;
}
import java.util.Scanner;
public class F
{
public static void main(String []args){
Scanner input = new Scanner(System.in);
int cases = input.nextInt();
for(int x=0; x<cases; x++){
double a = input.nextDouble();
//input.nextLine();
String o = input.next();
double b = input.nextDouble();
if(o.equals("+")){
double c = a+b;
System.out.println(String.format("%.2f", c));
}
else if(o.equals("-")){
double c = a-b;
System.out.println(String.format("%.2f", c));
}
else if(o.equals("*")){
double c = a*b;
System.out.println(String.format("%.2f", c));
}
else if(o.equals("/")){
if(b==0)
System.out.println("NaN");
else{
double c = a/b;
System.out.println(String.format("%.2f", c));
}
}
}
}
}
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] inputs = br.readLine().split(" ");
int d = Integer.parseInt(br.readLine());
int[] n = new int[inputs.length];
for (int j = 0; j < inputs.length; j++) {
n[j] = Integer.parseInt(inputs[j]);
}
Arrays.sort(n);
List<Integer> index = new ArrayList<>();
for (int j = 0; j < n.length - 1; j++) {
for (int i = j + 1; i < n.length; i++) {
if (n[i] > n[j] + d) {
break;
} else if (n[j] + d == n[i]) {
index.add(j);
index.add(i);
}
}
}
if (!index.isEmpty()) {
System.out.print("Pair found: ");
for (int j = 0; j < index.size(); j += 2) {
System.out.printf("(%d, %d)", n[index.get(j)], n[index.get(j+1)]);
if (j != index.size() - 2) {
System.out.print(", ");
}
}
} else {
System.out.println("No Pair Found");
}
}
}
//package prosolve_im26c4u;
import java.util.*;
import java.io.*;
import java.util.regex.Pattern;
public class Main {
// public static void main(String[] args) throws IOException{
// BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// int numCases = Integer.parseInt(br.readLine());
//
// for(int i=0; i< numCases; i++){
// TreeMap<String, Integer> map = new TreeMap<>();
// int numWords = Integer.parseInt(br.readLine());
// for(int j=0; j<numWords; j++){
// String[] a = br.readLine().split("\t");
// if(!map.containsKey(a[0])){
// map.put(a[0], 0);
// }
// map.put(a[0], map.get(a[0])+1);
// }
//
// for(Map.Entry<String, Integer> m : map.entrySet()){
// System.out.println(m.getValue()+"\t"+m.getKey());
//
// }
// if(i!=numCases-1) System.out.println("");
// }
// }
// public static void main(String arg[])throws IOException{
// BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// String s = br.readLine();
// String ans = s.replaceAll("[^A-Za-z]","");
// System.out.println(ans);
// }
// public static boolean composite[] = new boolean[10001];
// public static int primeF[] = new int[10001];
// public static void soe(int up){
// int sqrt = (int)Math.sqrt(up);
// for(int i=2;i<=sqrt;i++){
// if(!composite[i]){
// for(int j=i*i;j<=up;j+=i){
//// System.out.println(j);
// composite[j] = true;
// if(primeF[j]==0){
// primeF[j] = i;
//// System.out.println(primeF[j]);
// }else{
// primeF[j] = Math.min(i,primeF[j]);
// }
// }
// }
// }
// }
// public static void main (String args[]) throws IOException{
// String input = "a.in";
// String output = "a.out";
// boolean file = false;
// BufferedReader br;
// if(file)
// br = new BufferedReader(new FileReader(input));
// else
// br = new BufferedReader(new InputStreamReader(System.in));
// PrintWriter pr;
// if(file){
// pr = new PrintWriter(new FileWriter(output));
// }else{
// pr = new PrintWriter(System.out);
// }
// soe(10000);
//
// int T = Integer.parseInt(br.readLine());
// for(int i=0;i<T;i++){
// int N = Integer.parseInt(br.readLine());
// if(primeF[N]==0){
// System.out.println("Prime");
// }else{
// System.out.println(primeF[N]);
// }
// }
//
// pr.close();
// }
public static void main (String args[]) throws IOException{
String input = "a.in";
String output = "a.out";
boolean file = false;
BufferedReader br;
if(file)
br = new BufferedReader(new FileReader(input));
else
br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pr;
if(file){
pr = new PrintWriter(new FileWriter(output));
}else{
pr = new PrintWriter(System.out);
}
int N = Integer.parseInt(br.readLine());
long dp[][] = new long[2][1001];
dp[0][1] = 1;
dp[1][1] = 1;
for(int i=2;i<=1000;i++){
dp[0][i] = dp[1][i-1];
dp[1][i] = dp[0][i-1]+dp[1][i-1];
}
for(int i=0;i<N;i++){
int t = Integer.parseInt(br.readLine());
System.out.println(dp[0][t]+dp[1][t]);
}
pr.close();
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
public class I {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int t = Integer.parseInt(br.readLine());
while(t>0){
BigInteger num = new BigInteger(br.readLine());
if(num.isProbablePrime(100)){
sb.append("Prime");
}
else{
sb.append(smallestPF(num.intValue()));
}
sb.append("\n");
t--;
}
System.out.println(sb.toString());
}
public static int smallestPF(int x){
int fac = 2;
while(true){
if(x%fac==0){
return fac;
}
else{
fac++;
}
}
}
}
n = int(input())
x = []
y = []
for _ in range(n):
a, b = list(map(float, input().strip().split(' ')))
x.append(a)
y.append(b)
x_mean = sum(x) / len(x)
y_mean = sum(y) / len(y)
up = 0
down = 0
for a, b in zip(x, y):
up += (a - x_mean) * (b - y_mean)
down += (a - x_mean) ** 2
beta = up / down
alpha = y_mean - beta * x_mean
print("%.4f %.4f" % (beta, alpha))
n = int(input())
for _ in range(n):
print("%.4f" % (beta * float(input()) + alpha))
#include<iostream>
#include <iomanip>
using namespace std;
int main(){
int T;
cin >> T;
float f1,f2;
char c;
for(int i=0;i<T;i++){
cin >> f1 >> c >> f2;
if(c == '-'){
f1 -=f2;
}
else if(c == '+'){
f1 +=f2;
}
else if(c == '*'){
f1 *=f2;
}
else if(c == '/'){
if(f2 != 0)
f1 /=f2;
else
f1 = -1;
}
if(f1 > 0){
cout << fixed << setprecision(2) << f1 << " ";
}
else
cout << "NaN ";
}
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
float a, b;
cin >> a >> b;
float total = 0;
while(a--)
{
float x;
cin >> x;
total += x;
}
cout << ceil(total/b);
}
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int num[6];
for(int i=0;i<6;i++)
{
cin>>num[i];
}
for(int j=5;j>0;j--)
{
for(int d=0;d<j;d++)
{
num[d]=abs(num[d+1]-num[d]);
cout<<num[d]<<" ";
}
if(j!=1)
cout<<endl;
}
return 0;
}
t = int(input())
for ti in range(t):
left, op, right = input().split(' ')
if op == '/' and float(right) == 0:
print('NaN')
else:
ans = eval('{}{}{}'.format(left, op, right))
print('{:.2f}'.format(ans))
#include<bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sf(x) scanf("%d\n", &x)
#define pf(x) printf("%d\n", &x)
#define all(x) x.begin(), x.end
#define fill(a,x)memset(a,x,sizeof a)
#define size_a(a)sizeof(a) / sizeof(a[0])
#define dbg(x) cerr <<(#x) << "is" <<x<<'\n'
#define repi(i,a,n) for (int i = (int)a;i<(int)n;++i)
#define repll(i,a,n) for (int i = (ll)a;i<(ll)n;++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef vector<ii>vii;
typedef vector<int>vi;
// Global Variable Declaration
double a,b;
char o;
int T;
int main(){
cin >>T;
while(T--){
cin >> a >> o >> b;
if(o=='+')
cout<<fixed<<setprecision(2)<<(double)(a+b)<<endl;
else if(o=='-')
cout<<fixed<<setprecision(2)<<(double)(a-b)<<endl;
else if(o=='*')
cout<<fixed<<setprecision(2)<<(double)(a*b)<<endl;
else if(o=='/'){
if(b==0)
cout<<"NaN"<<endl;
else
cout<<fixed<<setprecision(2)<<(double)(a/b)<<endl;
}
else
cout<<"NaN"<<endl;
}
return 0;
}
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int test;
cin>>test;
for(int i=0;i<test;i++)
{
float a,b;
char sign;
cin>>a>>sign>>b;
if(sign=='+')
cout<<fixed<<setprecision(2)<<a+b<<endl;
if(sign=='-')
cout<<fixed<<setprecision(2)<<a-b<<endl;
if(sign=='*')
cout<<fixed<<setprecision(2)<<a*b<<endl;
if(sign=='/')
cout<<fixed<<setprecision(2)<<a/b<<endl;
}
return 0;
}
t = int(input())
a = []
a.append(1)
a.append(2)
for i in range(2, 1010):
a.append(a[i-1] + a[i-2])
while t > 0:
t -= 1
n = int(input())
print(a[n])
#include <bits/stdc++.h>
using namespace std;
int main()
{
int T, N;
cin>>T;
for (int i = 0; i < T; i++)
{
cin>>N;
if ((N % 2 != 0) && (N % 3 != 0) && (N % 5 != 0))
cout<<"Prime";
else
for (int i = 2; i < N; i++)
{
if (N % i == 0)
{
cout<<i;
break;
}
}
cout<<endl;
}
return 0;
}
inp = input()
for i in range(0, int(inp)):
req = input()
req2 = input()
req3 = input()
if req2=="+":
print(float(req)+float(req3))
elif req2=="-":
print(float(req)-float(req3))
elif req2=="*":
print(float(req)*float(req3))
elif req2=="/":
print(float(req)/float(req3))
else:
print("NaN")
#include<iostream>
#include <iomanip>
using namespace std;
int main(){
int T;
cin >> T;
float f1,f2;
char c;
for(int i=0;i<T;i++){
cin >> f1 >> c >> f2;
if(c == '-'){
f1 -=f2;
}
else if(c == '+'){
f1 +=f2;
}
else if(c == '*'){
f1 *=f2;
}
else if(c == '/'){
if(f2 != 0)
f1 /=f2;
else
f1 = -1;
}
if(f1 > 0){
cout << fixed << setprecision(2) << f1 << endl;
}
else
cout << "NaN" << endl;
}
}
#include <iostream>
using namespace std;
bool isPrime(int n)
{
int i;
if (n <=1) return false;
for (i=2; i<n; i++)
{
if (n%i==0)
{
return false;
}
}
return true;
}
int primeFactor (int x)
{
int b;
for (b=2; b<x; b++)
{
if (isPrime(b))
{
if (x%b==0) return b;
}
}
}
int main()
{
int a;
cin >> a;
if (isPrime(a)) cout << "Prime\n";
else cout << primeFactor(a) << "\n";
}
#include <iostream>
#include <iomanip>
using namespace std;
int cari(int a)
{
for (int i = 2; i <= a; i++)
{
if (a%i == 0)
{
return i;
}
}
}
int main()
{
int T,input,prime;
cin>>T;
while (T!=0)
{
cin>>input;
prime = cari(input);
if (prime == input) cout<<"Prime\n";
else cout<<prime<<endl;
T--;
}
}
#include<iostream>
#include <iomanip>
using namespace std;
int main(){
int T;
cin >> T;
float f1,f2;
char c;
for(int i=0;i<T;i++){
cin >> f1 >> c >> f2;
if(c == '-'){
f1 -=f2;
}
else if(c == '+'){
f1 +=f2;
}
else if(c == '*'){
f1 *=f2;
}
else if(c == '/'){
if(f2 != 0)
f1 /=f2;
else
f1 = -1;
}
if(f1 >= 0){
cout << fixed << setprecision(2) << f1 << endl;
}
else
cout << "NaN" << endl;
}
}
#include <iostream>
using namespace std;
bool isPrime(int n)
{
int i;
if (n <=1) return false;
for (i=2; i<n; i++)
{
if (n%i==0)
{
return false;
}
}
return true;
}
int primeFactor (int x)
{
int b;
for (b=2; b<x; b++)
{
if (isPrime(b))
{
if (x%b==0) return b;
}
}
}
int main()
{
int q, p;
cin >> q;
for (p=0; p<q; p++)
{
int a;
cin >> a;
if (isPrime(a)) cout << "Prime\n";
else cout << primeFactor(a) << "\n";
}
}
while True:
try:
line = input()
inputlist = [int(i) for i in line.split()]
newlist = inputlist.copy()
while len(newlist) != 1:
inputlist = newlist.copy()
newlist = []
for i in range(len(inputlist) - 1):
diff = inputlist[i + 1] - inputlist[i]
if diff < 0:
newlist.append(diff * -1)
else:
newlist.append(diff)
ans = ' '.join([str(n) for n in newlist])
print(ans)
except Exception as e:
# print(e)
break
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int T;
cin>>T;
float a,b,ans;
char o;
while(T != 0)
{
cin>>a>>o>>b;
if (a>=0 && b>= 0 && a <= 10000 && b <= 10000)
{
if (o == '+')
{
ans = a+b;
cout<<fixed<<setprecision(2)<<ans<<endl;
}
else if (o == '-')
{
ans = a-b;
cout<<fixed<<setprecision(2)<<ans<<endl;
}
else if (o == '*')
{
ans = a*b;
cout<<fixed<<setprecision(2)<<ans<<endl;
}
else if (o == '/')
{
ans = a/b;
cout<<fixed<<setprecision(2)<<ans<<endl;
}
else
{
cout<<"NaN"<<endl;
}
}
else cout<<"NaN"<<endl;
T--;
}
}
import java.util.*;
import java.io.*;
class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String tmp = br.readLine();
String[] numbers = tmp.split(" ");
int[] numInt = new int[numbers.length];
for(int i=0; i<numbers.length; i++){
numInt[i] = Integer.parseInt(numbers[i]);
}
for(int j=0; j<numInt.length-1; j++){
for(int k=0; k<numInt.length-1-j; k++){
numInt[k] = Math.max(numInt[k], numInt[k+1]) - Math.min(numInt[k], numInt[k+1]);
System.out.print(numInt[k]);
if(k<numInt.length-2-j){
System.out.print(" ");
}
}
System.out.println("");
}
}
}
#include<iostream>
using namespace std;
int main()
{
int t;
int b;
cin>>t;
for (int i = 0; i < t; i++)
{
int a;
cin>>a;
for ( int i = 2; i < 10; i++)
{
if (( a % i == 0 ) && ( a!=i ))
{
b = i;
break;
}
}
if ( b == 0)
{
cout<<"Prime";
cout<<"\n";
}
else
{
cout<<b;
cout<<"\n";
}
b = 0;
}
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
int T, N;
cin>>T;
for (int i = 0; i < T; i++)
{
cin>>N;
if (N % 2 != 0 && N % 3 != 0 && N % 4 != 0 && N % 5 != 0 && N % 6 != 0 && N % 7 != 0 && N % 8 != 0 && N % 9 != 0)
cout<<"Prime";
else
for (int i = 2; i < N; i++)
{
if (N % i == 0)
{
cout<<i;
break;
}
}
cout<<endl;
}
return 0;
}
//package prosolve_im26c4u;
import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.util.regex.Pattern;
public class Main {
// public static void main(String[] args) throws IOException{
// BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// int numCases = Integer.parseInt(br.readLine());
//
// for(int i=0; i< numCases; i++){
// TreeMap<String, Integer> map = new TreeMap<>();
// int numWords = Integer.parseInt(br.readLine());
// for(int j=0; j<numWords; j++){
// String[] a = br.readLine().split("\t");
// if(!map.containsKey(a[0])){
// map.put(a[0], 0);
// }
// map.put(a[0], map.get(a[0])+1);
// }
//
// for(Map.Entry<String, Integer> m : map.entrySet()){
// System.out.println(m.getValue()+"\t"+m.getKey());
//
// }
// if(i!=numCases-1) System.out.println("");
// }
// }
// public static void main(String arg[])throws IOException{
// BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// String s = br.readLine();
// String ans = s.replaceAll("[^A-Za-z]","");
// System.out.println(ans);
// }
// public static boolean composite[] = new boolean[10001];
// public static int primeF[] = new int[10001];
// public static void soe(int up){
// int sqrt = (int)Math.sqrt(up);
// for(int i=2;i<=sqrt;i++){
// if(!composite[i]){
// for(int j=i*i;j<=up;j+=i){
//// System.out.println(j);
// composite[j] = true;
// if(primeF[j]==0){
// primeF[j] = i;
//// System.out.println(primeF[j]);
// }else{
// primeF[j] = Math.min(i,primeF[j]);
// }
// }
// }
// }
// }
// public static void main (String args[]) throws IOException{
// String input = "a.in";
// String output = "a.out";
// boolean file = false;
// BufferedReader br;
// if(file)
// br = new BufferedReader(new FileReader(input));
// else
// br = new BufferedReader(new InputStreamReader(System.in));
// PrintWriter pr;
// if(file){
// pr = new PrintWriter(new FileWriter(output));
// }else{
// pr = new PrintWriter(System.out);
// }
// soe(10000);
//
// int T = Integer.parseInt(br.readLine());
// for(int i=0;i<T;i++){
// int N = Integer.parseInt(br.readLine());
// if(primeF[N]==0){
// System.out.println("Prime");
// }else{
// System.out.println(primeF[N]);
// }
// }
//
// pr.close();
// }
public static void main (String args[]) throws IOException{
String input = "a.in";
String output = "a.out";
boolean file = false;
BufferedReader br;
if(file)
br = new BufferedReader(new FileReader(input));
else
br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pr;
if(file){
pr = new PrintWriter(new FileWriter(output));
}else{
pr = new PrintWriter(System.out);
}
int N = Integer.parseInt(br.readLine());
BigInteger b[] = new BigInteger[1001];
b[0] = BigInteger.ONE;
b[1] = new BigInteger("2");
for(int i=2;i<=1000;i++){
b[i] = b[i-1].add(b[i-2]);
}
for(int i=0;i<N;i++){
int t = Integer.parseInt(br.readLine());
System.out.println(b[t]);
}
pr.close();
}
}
import java.util.*;
public class QI{
public static void main(String arg[])
{
Scanner in = new Scanner(System.in);
int t = in.nextInt();
int num2[] = new int[t];
for(int i=0; i<t; i++)
{
num2[i] = in.nextInt();
}
for(int i=0; i<t; i++)
{
int count = 0;
for(int j=1; j<=num2[i]; j++)
{
if((num2[i]%j)==0)
{
count++;
}
}
if(count==2)
System.out.println("Prime");
else
{
for(int k=2; k<num2[i]; k++)
{
if(num2[i]%k==0)
{
System.out.println(k);
break;
}
}
}
}
}
}
n,q=map(int,input().split())
sensor=[]
for _ in range(n):
sensor.append(list(map(int,input().split())))
for _ in range(q):
reading=int(input())
for j in range(n):
if sensor[j][0]==reading:
if j+1<n:
print(sensor[j][1],sensor[j][0],sensor[j+1][0])
else:
print(sensor[j][1],sensor[j][0],-1)
break
elif sensor[j][0]>reading:
if j==0:
print(-1,-1,reading,sensor[j][0])
else:
print(sensor[j-1][1],sensor[j-1][0],sensor[j][0])
break
if j==n-1:
print(sensor[j][1],sensor[j][0],-1)
���4j
67 89
:
;<
3=
>?
6
@A
BC
D
3EFG
HI 8JK
LMNOP<init>()VCodeLineNumberTableLocalVariableTablethisLa;main([Ljava/lang/String;)Vnum1Inum2iargs[Ljava/lang/String;sc2Ljava/util/Scanner;lineLjava/lang/String;array
differencesbLjava/lang/StringBuilder;
StackMapTable(Q
SourceFilea.javajava/util/ScannerRSTUVW\W+XYZ[java/lang/StringBuilder\]^_[(`abc,)dW,(efPair Found:ghi
No Pair Foundajava/lang/Objectjava/lang/Stringjava/lang/SysteminLjava/io/InputStream;(Ljava/io/InputStream;)VnextLine()Ljava/lang/String;split'(Ljava/lang/String;)[Ljava/lang/String;nextInt()Ijava/lang/IntegerparseInt(Ljava/lang/String;)Ilengthappend-(Ljava/lang/String;)Ljava/lang/StringBuilder;valueOf(I)Ljava/lang/String;toStringoutLjava/io/PrintStream;java/io/PrintStreamprint(Ljava/lang/String;)V!/*�� !"� ��Y��L+�M,�N+�6� Y�
:6-���-�d��-2�6-`2�6d�l��5� Y�
���������W�2� Y�
���������W���f��#�� Y�
���������J
&09BMW_����� �"\ B~#$Ms%$)�&$�'(�)*�+,�-(�.$&�/01'�)232 �g�.�'45
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
float a, b, ans;
int t;
char o;
cout<<"Enter number of test cases: ";
cin>>t;
if(t>0 && t<=100)
{
for(int i=0; i<t; i++)
{
ans=0;
cout<<"Enter number A: ";
cin>>a;
cout<<"Enter number B: ";
cin>>b;
cout<<"Enter operation: (+, -, *, /) : ";
cin>>o;
if(o == '+')
{
ans = a + b;
}
else if(o == '-')
{
ans = a - b;
}
else if(o == '*')
{
ans = a * b;
}
else if(o == '/')
{
ans = a / b;
}
else
cout<<"\nNaN";
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<ans<<endl;
}
}
getch();
return 0;
}
s = input().split()
nums = [int(n) for n in s]
d = int(input())
ans = []
for i in range(len(nums)):
for j in range(i+1,len(nums)):
if abs(nums[i]-nums[j])==d:
ans.append((nums[i], nums[j]))
if len(ans)==0:
print('No Pair Found')
else:
s=[]
for t in ans:
s.append('({}, {})'.format(t[0],t[1]))
print("Pair Found:", ', '.join(s))
import math
tc = int(input())
for i in range(tc):
str1 = input()
if("+" in str1):
eqn = str1.split("+")
if not(math.isnan( float(eqn[0]) + float(eqn[1]))):
print("{:.2f}".format( float(eqn[0]) + float(eqn[1])))
else:
print("NaN")
elif("-" in str1):
eqn = str1.split("-")
if not(math.isnan(float(eqn[0]) * float(eqn[1]))):
print("{:.2f}".format( float(eqn[0]) - float(eqn[1])))
else:
print("NaN")
elif("*" in str1):
eqn = str1.split("*")
if not(math.isnan( float(eqn[0]) * float(eqn[1]))):
print("{:.2f}".format( float(eqn[0]) * float(eqn[1])))
else:
print("NaN")
else:
eqn = str1.split("/")
if not(math.isnan( float(eqn[0]) / float(eqn[1]))):
print("{:.2f}".format( float(eqn[0]) / float(eqn[1])))
else:
print("NaN")
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int T;
cin>>T;
float a,b,ans;
char o;
while(T != 0)
{
cin>>a>>o>>b;
if (o == '+')
{
ans = a+b;
cout<<fixed<<setprecision(2)<<ans<<endl;
}
else if (o == '-')
{
ans = a-b;
cout<<fixed<<setprecision(2)<<ans<<endl;
}
else if (o == '*')
{
ans = a*b;
cout<<fixed<<setprecision(2)<<ans<<endl;
}
else if (o == '/')
{
if (b == 0) cout<<"NaN"<<endl;
else {
ans = a/b;
cout<<fixed<<setprecision(2)<<ans<<endl;
}
}
else
{
cout<<"NaN"<<endl;
}
T--;
}
}
import java.util.Scanner;
public class A
{
public static void main(String []args){
Scanner input = new Scanner(System.in);
int flag = 0;
String lines = input.nextLine();
int s = input.nextInt();
String arr[] = lines.split(" ");
for(int x=0; x<arr.length-1; x++){
int com = Integer.parseInt(arr[x+1])-Integer.parseInt(arr[x]);
if(com==s){
if(flag>0)
System.out.print(", ");
flag++;
if(flag==1)
System.out.print("Pair Found:" );
System.out.print("("+Integer.parseInt(arr[x])+", "+Integer.parseInt(arr[x+1])+")");
}
}
if(flag==0)
System.out.println("No Pair Found");
}
}
testcase = int(input())
for x in range(testcase):
length = int(input())
total = 2**length
subtract = 0
for i in range(length):
subtract+=i
print(total-subtract)
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
int n, q;
vector<pii> v;
int main() {
scanf("%d%d", &n, &q);
int a, b;
for (int i = 0; i < n; ++i) {
scanf("%d%d", &a, &b);
v.push_back(make_pair(a, b));
}
sort(all(v));
while (q--) {
scanf("%d", &a);
if (v[0].F > a) {
printf("%d %d %d\n", -1, -1, v[0].F);
continue;
}
int l = 0, r = n - 1, mid;
while (l < r) {
mid = l + (r - l + 1) / 2;
if (v[mid].F <= a) l = mid;
else r = mid - 1;
}
printf("%d %d", v[l].S, v[l].F);
if (l == n - 1) printf(" %d\n", -1);
else printf(" %d\n", v[l+1].F);
}
return 0;
}
s = input().split()
nums = [int(n) for n in s]
nums.sort()
d = int(input())
ans = []
for i in range(len(nums)):
for j in range(i+1,len(nums)):
if abs(nums[i]-nums[j])==d:
ans.append((nums[i], nums[j]))
if len(ans)==0:
print('No Pair Found')
else:
s=[]
for t in ans:
s.append('({}, {})'.format(t[0],t[1]))
print("Pair Found:", ', '.join(s))
try:
while True:
n, k, d = map(int, input().strip().split(" "))
A = [0 for x in range(n)]
for ___ in range(d):
a, b, h = map(int, input().strip().split(" "))
for i in range(a, b+1):
A[i-1] = (A[i-1] + h) % k
j = 1
for i in range(0, n-1):
if (A[i+1] != A[i]):
j+=1
print(j)
except:
pass
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int T;
cin>>T;
float a,b,ans;
char o;
while(T != 0)
{
cin>>a>>o>>b;
if (a>=0 && b>= 0 && a <= 10000 && b <= 10000)
{
if (o == '+')
{
ans = a+b;
cout<<fixed<<setprecision(2)<<ans<<endl;
}
else if (o == '-')
{
ans = a-b;
cout<<fixed<<setprecision(2)<<ans<<endl;
}
else if (o == '*')
{
ans = a*b;
cout<<fixed<<setprecision(2)<<ans<<endl;
}
else if (o == '/')
{
if (b == 0) cout<<"NaN"<<endl;
else {
ans = a/b;
cout<<fixed<<setprecision(2)<<ans<<endl;
}
}
else
{
cout<<"NaN"<<endl;
}
}
else cout<<"NaN"<<endl;
T--;
}
}
import math
tc = int(input())
for i in range(tc):
str1 = input()
if("+" in str1):
eqn = str1.split("+")
if not(math.isnan( float(eqn[0]) + float(eqn[1]))):
print("{:.2f}".format( float(eqn[0]) + float(eqn[1])))
else:
print("NaN")
elif("-" in str1):
eqn = str1.split("-")
if not(math.isnan(float(eqn[0]) * float(eqn[1]))):
print("{:.2f}".format( float(eqn[0]) - float(eqn[1])))
else:
print("NaN")
elif("*" in str1):
eqn = str1.split("*")
if not(math.isnan( float(eqn[0]) * float(eqn[1]))):
print("{:.2f}".format( float(eqn[0]) * float(eqn[1])))
else:
print("NaN")
else:
eqn = str1.split("/")
if not(float(eqn[1]) == 0):
if not(math.isnan( float(eqn[0]) / float(eqn[1]))):
print("{:.2f}".format( float(eqn[0]) / float(eqn[1])))
else:
print("NaN")
else:
print("NaN")
array = [int(x) for x in input().split(' ')]
diff = int(input())
pair = set([])
array = sorted(array)
for i in range(len(array)-1):
for j in range(i + 1, len(array), 1):
dist = abs(array[i] - array[j])
if dist == diff:
pair.add((array[i], array[j]))
if len(pair) == 0:
print('No Pair Found')
else:
pair = list(pair)
pair = sorted(pair, key=lambda x: x[0])
s = ''
for k, (l, r) in enumerate(pair):
s += '({}, {})'.format(l, r)
if k != len(pair) - 1:
s += ', '
print('Pair Found: {}'.format(s))
#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;
int main()
{
int n;
cin >> n;
cout << fixed << showpoint << setprecision(4);
double x[n], y[n];
for(int a = 0; a < n; a++)
{
cin >> x[a] >> y[a];
}
double my, mx, ty = 0, tx = 0;
for(int b = 0; b < n; b++)
{
tx += x[b];
ty += y[b];
}
mx = tx / n;
my = ty / n;
double alpha, beta, sigma = 0, sigma2 = 0, sqr, sum;
for(int c = 0; c < n; c++)
{
sigma = sigma + ((x[c] - mx) * (y[c] - my));
sum = x[c] - mx;
sqr = pow(sum,2);
sigma2 = sigma2 + sqr;
}
beta = sigma / sigma2;
alpha = my - (beta * mx);
cout << beta << " " << alpha << endl;
int m;
cin >> m;
double out;
for(int d = 0; d < m; d++)
{
cin >> out ;
double ret = alpha + (beta * out);
cout << ret << endl;
}
}
import java. util.*;
public class a
{
public static void main (String[] args)
{
Scanner in=new Scanner(System.in);
ArrayList a=new ArrayList();
String b= in.nextLine();
int e=in.nextInt();
int count=0;
StringTokenizer c=new StringTokenizer(b, " ");
while (c.hasMoreTokens())
{
a.add(Integer.parseInt(c.nextToken()));
}
int[] d= new int[a.size()];
boolean found=false;
for (int i=0; i<a.size(); i++)
{
d[i]=Integer.parseInt(a.get(i).toString());
}
Arrays.sort(d);
for (int i=0; i<d.length-1; i++)
{
if (d[i+1]-d[i]==e)
{
found=true;
break;
}
}
for (int i = 0; i < d.length-1; i++) {
if (d[i + 1] - d[i] == e)
count++;
}
if(found)
{
System.out.print("Pair Found: " );
for (int i = 0; i < d.length-1; i++) {
if (d[i + 1] - d[i] == e) {
System.out.print("(" + d[i] + ", " + d[i + 1] + ")");
count--;
if(count>0)
{
System.out.print(", ");
}
}
}
found = true;
}
if (!found)
System.out.print("No Pair Found");
}
}
#include <iostream>
#include<conio.h>
using namespace std;
int main()
{
int test;
float first, second;
char operators;
float result;
cout<<"Enter number of test cases : ";
cin>>test;
while(test != 0)
{
cout<<"\n\nEnter expression : (NUMBER OPERAND NUMBER) "<<endl;
cin>>first>>operators>>second;
switch(operators)
{
case '+' : result = first + second;
break;
case '-' : result = first - second;
break;
case '*' : result = first * second;
break;
case '/' : if(second != 0.0)
result = first/second;
else
cout<<"NaN";
break;
default : cout<<operators<<"is unrecognised operation"<<endl;
return 0;
}
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<"\n"<<result;
test--;
}
return 0;
}
import java.util.*;
import java.io.*;
class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String tmp = br.readLine();
StringTokenizer st = new StringTokenizer(tmp);
int cases1 = Integer.parseInt(st.nextToken());
int cases2 = Integer.parseInt(st.nextToken());
// TreeMap<Integer, Integer> map = new TreeMap<>();
ArrayList<CustomNumber> arr = new ArrayList<>();
for(int i=0; i<cases1; i++){
StringTokenizer st2 = new StringTokenizer(br.readLine());
arr.add(new CustomNumber(Integer.parseInt(st2.nextToken()), Integer.parseInt(st2.nextToken())));
}
CustomNumber[] numbersArr = new CustomNumber[arr.size()];
arr.toArray(numbersArr);
Arrays.sort(numbersArr);
for(int i=0; i<cases2; i++){
int n = Integer.parseInt(br.readLine());
boolean check = false;
for(int j=0; j<numbersArr.length; j++){
if(n < numbersArr[j].num1){
if(j==0) {
System.out.println("-1 -1 " + numbersArr[j].num1);
check = true;
break;
}
else{
System.out.println(numbersArr[j-1].num2 + " " + numbersArr[j-1].num1 + " " + numbersArr[j].num1);
check = true;
break;
}
}
}
if(!check){
System.out.println(numbersArr[numbersArr.length-1].num2 + " " + numbersArr[numbersArr.length-1].num1 + " -1");
}
}
}
}
class CustomNumber implements Comparable<CustomNumber>{
int num1, num2;
public CustomNumber(int n1, int n2){
num1 = n1;
num2 = n2;
}
@Override
public int compareTo(CustomNumber o) {
return (num1 - o.num1);
}
}
import sys
y = [2, 3]
for i in range(2, 1000):
y.append(y[i - 1] + y[i - 2])
x = sys.stdin.read().strip().split('\n')
x.pop(0)
for k in x:
print(y[int(k) - 1])
#include <bits/stdc++.h>
using namespace std;
int main()
{
int T, N;
cin>>T;
for (int i = 0; i < T; i++)
{
cin>>N;
if (N == 2 || N == 3 || N == 5 || N == 7)
{
cout<<"Prime";
}
else
{
if (N % 2 != 0 && N % 3 != 0 && N % 4 != 0 && N % 5 != 0 && N % 6 != 0 && N % 7 != 0 && N % 8 != 0 && N % 9 != 0)
cout<<"Prime";
else
{
for (int i = 2; i < N; i++)
{
if (N % i == 0)
{
cout<<i;
break;
}
}
}
}
cout<<endl;
}
return 0;
}
tc = int(input())
for i in range(tc):
num = int(input())
flag = False
if num==2 or num==3 or num==5 or num==7:
print ("Prime")
continue
if num%2!=0:
flag = True
else:
print ("2")
continue
if num%3!=0:
flag = True
else:
print ("3")
continue
if num%5!=0:
flag = True
else:
print ("5")
continue
if num%7!=0:
flag = True
else:
print ("7")
continue
if flag:
print("Prime")
#include <bits/stdc++.h>
using namespace std;
int main(){
vector<int> ex;
int tm;
while(cin>>tm){
ex.push_back(tm);
}
for(int i=1;i<ex.size();i++){
int l=ex[i-1];
for(int j=i;j<ex.size();j++){
cout<<abs(ex[j]-l)<<((j+1==ex.size())?"":" ");
int pl=l;
l=ex[j];
// cout<<l<<endl;
ex[j]=abs(ex[j]-pl);
}
cout<<endl;
}
}
import java.util.*;
class a{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
String inputT = sc.nextLine();
int inputN = Integer.parseInt(sc.nextLine());
String[] s = inputT.split(" ");
Integer[] arr = new Integer[s.length];
for(int i=0; i<s.length; i++){
arr[i] = Integer.parseInt(s[i]);
}
String output = "";
boolean found = false;
for(int i = 0; i<arr.length; i++){
int a = arr[i];
for(int j=0 ; j<arr.length; j++){
int b = arr[j];
if(b > a && (b-a==inputN)){
if(output.indexOf("("+a+","+b+")") != 0)
output += "("+a+","+b+")";
found = true;
}
}
}
if(found) System.out.println("\nPair Found: "+output);
else System.out.println("\nNo Pair Found!");
}
}
#include<iostream>
using namespace std;
int main()
{
int t, b;
cin>>t;
int arr[t];
for (int m = 0; m < t; m++)
{
cin>>arr[m];
}
for (int m = 0; m < t; m++)
{
for ( int i = 2; i < 10; i++)
{
if (( arr[m] % i == 0 ) && ( arr[m]!=i ))
{
b = i;
break;
}
}
if ( b == 0)
{
cout<<"Prime";
cout<<"\n";
}
else
{
cout<<b;
cout<<"\n";
}
b = 0;
}
}
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
int n, q;
pair<double, double> arr[110];
int main() {
cin >> n;
double xv = 0, yv = 0;
for (int i = 0; i < n; ++i) {
cin >> arr[i].F >> arr[i].S;
xv += arr[i].F;
yv += arr[i].S;
}
xv /= n;
yv /= n;
double A, B;
double fo2 = 0, t7t = 0;
for (int i = 0; i < n; ++i) {
fo2 += (arr[i].F - xv) * (arr[i].S - yv);
t7t += (arr[i].F - xv) * (arr[i].F - xv);
}
B = fo2 / t7t;
A = yv - B * xv;
printf("%.4f %.4f\n", B, A);
scanf("%d", &q);
while (q--) {
cin >> xv;
printf("%.4f\n", A + B * xv);
}
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int T;
cin>>T;
if((T/2)%2!=0&&T/2!=0)
{
cout<<"Prime";
}
else
{
for(int i=1;i<=T;++i)
{
if(T%i==0)
cout<<i<<endl;
}
}
}
testcase = int(input())
for i in range(testcase):
line = input()
# .split()
# a = line[0]
# o = line[1]
# b = line[2]
# op = a + o + b
try:
result = eval(line)
except Exception as e:
print('NaN')
continue
print("%.2f" % (float(result)))
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] inputs = br.readLine().split(" ");
}
}
#include<bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sf(x) scanf("%d\n", &x)
#define pf(x) printf("%d\n", &x)
#define all(x) x.begin(), x.end
#define fill(a,x)memset(a,x,sizeof a)
#define size_a(a)sizeof(a) / sizeof(a[0])
#define dbg(x) cerr <<(#x) << "is" <<x<<'\n'
#define repi(i,a,n) for (int i = (int)a;i<(int)n;++i)
#define repll(i,a,n) for (int i = (ll)a;i<(ll)n;++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef vector<ii>vii;
typedef vector<int>vi;
// Global Variable Declaration
int T;
int x;
int main(){
cin >> T;
while(T--){
int cnt = 0;
cin >> x;
repi(i,1,x+1){
if(x%i==0)
cnt++;
}
if(cnt==2)
cout<<"Prime"<<endl;
else{
repi(i,2,x+1){
if(x%i==0){
cout<<i<<endl;break;
}
}
}
}
return 0;
}
import java.util.*;
import java.io.*;
import java.math.BigInteger;
class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int cases = Integer.parseInt(br.readLine());
for(int i=0; i<cases; i++){
String line = br.readLine();
if(line.contains("+")) {
int pos = line.indexOf("+");
float num1 = Float.parseFloat(line.substring(0, pos));
float num2 = Float.parseFloat(line.substring(pos+1));
System.out.printf("%.2f\n", (num1+num2));
}
if(line.contains("-")) {
int pos = line.indexOf("-");
float num1 = Float.parseFloat(line.substring(0, pos));
float num2 = Float.parseFloat(line.substring(pos+1));
System.out.printf("%.2f\n", (num1-num2));
}
if(line.contains("*")) {
int pos = line.indexOf("*");
float num1 = Float.parseFloat(line.substring(0, pos));
float num2 = Float.parseFloat(line.substring(pos+1));
System.out.printf("%.2f\n", (num1*num2));
}
if(line.contains("/")) {
int pos = line.indexOf("/");
float num1 = Float.parseFloat(line.substring(0, pos));
float num2 = Float.parseFloat(line.substring(pos+1));
if(num2 == 0) System.out.println("NaN");
else System.out.printf("%.2f\n", (num1/num2));
}
}
}
}
#include <iostream>
#include <cstring>
#include <iomanip>
using namespace std;
int main()
{
int list[10];
int list2[2];
int diff;
int a ;
int b;
int c;
cout << "List" << endl;
for(int i=0;i<10;i++)
{
cin >> list[i];
}
cout << "Difference: ";
cin >> diff;
for (int i = 0; i<list[i];i++)
{
a = list[i];
b = list[i+1];
if(b-a == diff)
{
cout<<"Pair Found"<<"(" << a <<","<< b << ")"<<endl;
}
else
{
cout<<"No Pair Found"<<endl;
}
}
}
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
for (int i = Integer.parseInt(br.readLine()); i-- > 0;) {
String[] inputs = br.readLine().split(" ");
if (isPrime(Integer.parseInt(inputs[0]))) {
System.out.println("Prime");
} else {
System.out.println(calcPrimeF(Integer.parseInt(inputs[0])));
}
}
}
public static boolean isPrime(int a) {
if (a == 1 || (a % 2 == 0&&a!=2) || a % 3 == 0) {
return false;
}
if (a < 4) {
return true;
}
if (a < 9) {
return true;
}
int r = (int) Math.sqrt(a);
int f = 5;
while (f <= r) {
if (a % f == 0) {
return false;
}
if (a % (f + 2) == 0) {
return false;
}
f += 6;
}
return true;
}
public static int calcPrimeF(int a) {
int i =2;
for ( ; i <= Math.sqrt(a); i++) {
if (a % i == 0) {
if (isPrime(i)) {
return i;
}
}
}
return i;
}
}
#include<iostream>
#include<sstream>
using namespace std;
int main()
{
int num[10];
string input;
getline(cin,input);
stringstream ss(input);
int counter = 0;
while(ss>>num[counter])
{
counter++;
}
int diff;
cin>>diff;
int a,b;
bool found =true;
bool first = true;
for(int i=0;i<counter-1;i++)
{
a=num[i+1];
b=num[i];
if(a-b==diff){
if(found)
cout<<"Pair Found: ";
found = false;
if(!first)cout<<",";
cout<<"("<<b<<", "<<a<<")";
first=false;
}
}
if(found)
{
cout<<"No Pair Found"<<endl;
}
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int t, b;
cin>>t;
int arr[t];
for (int m = 0; m < t; m++)
{
cin>>arr[m];
}
cout<<"\n";
for (int m = 0; m < t; m++)
{
for ( int i = 2; i < 10; i++)
{
if (( arr[m] % i == 0 ) && ( arr[m]!=i ))
{
b = i;
break;
}
}
if ( b == 0)
{
cout<<"Prime";
cout<<"\n";
}
else
{
cout<<b;
cout<<"\n";
}
b = 0;
}
}
def key(x):
return x[1]
nums = [int(x) for x in input().split()]
diff = int(input())
list1 = []
for i in nums:
for k in nums:
if(i < k):
if( abs(i-k) is diff):
list1.append((i,k))
list1 = sorted(list1,key=key)
if(len(list1) > 0):
output = ""
for i in list1:
output += ", ({}, {})".format(i[0],i[1])
print("Pair Found: {}".format(output[1:]))
else:
print("No Pair Found")
tc = int(input())
for i in range(tc):
num = int(input())
flag = False
if num==2 or num==3 or num==5 or num==7:
print ("Prime")
continue
elif num == 1:
print(1)
continue
if num%2!=0:
flag = True
else:
print ("2")
continue
if num%3!=0:
flag = True
else:
print ("3")
continue
if num%5!=0:
flag = True
else:
print ("5")
continue
if num%7!=0:
flag = True
else:
print ("7")
continue
if flag:
print("Prime")
import math
import sys
x = list(map(int, sys.stdin.read().strip().split('\n')))
x.pop(0)
def f(x):
if x < 2: return False
if x == 2: return True
if x % 2 == 0: return False
for i in range(3, int(math.sqrt(x)) + 1, 2):
if x % i == 0:
return False
return True
y = [k for k in range(2, 10000) if f(k)]
for k in x:
if k in y:
print("Prime")
else:
for i in range(2, k):
if (k % i == 0) and (i in y):
print(i)
break
import math
while True:
try:
line1 = input().split()
line2 = input().split()
s = 0
for i in line2:
s += int(i)
s = math.ceil(s / int(line1[1]))
print(s)
except Exception as e:
# print(e)
break
#include <bits/stdc++.h>
using namespace std;
int main()
{
int T, N;
cin>>T;
if( T >= 1 && T <= 50)
{
for (int i = 0; i < T; i++)
{
cin>>N;
if (N >= 2 && N <= 10000)
{
if (N == 2 || N == 3 || N == 5 || N == 7)
{
cout<<"Prime";
}
else
{
if (N % 2 != 0 && N % 3 != 0 && N % 4 != 0 && N % 5 != 0 && N % 6 != 0 && N % 7 != 0 && N % 8 != 0 && N % 9 != 0)
cout<<"Prime";
else
{
for (int i = 2; i < N; i++)
{
if (N % i == 0)
{
cout<<i;
break;
}
}
}
}
cout<<endl;
}
else
cout<<"The number of N is either less than 2 or larger than 10000.";
}
}
else
cout<<"The number of T is larger than 50.";
return 0;
}
#include <iostream>
#include <cstring>
#include <iomanip>
using namespace std;
int main()
{
int list[10];
int list2[2];
int diff;
int a ;
int b;
cout << "List" << endl;
for(int i=0;i<10;i++)
{
cin >> list[i];
}
cout << "Difference: ";
cin >> diff;
for (int i = 0; i<list[i];i++)
{
a = list[i];
b = list[i+1];
if(b-a == diff)
{
cout<<"Pair Found"<<"(" << a <<","<< b << ")"<<endl;
}
else
{
cout<<"No Pair Found"<<endl;
}
}
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
char s[100000];
cin.getline(s, 9999);
char* token = strtok(s, " ");
vector<int> v;
while(token)
{
v.push_back(atoi(token));
token = strtok(NULL, " ");
}
int temp;
int sss = 1;
while(sss < v.size())
{
for(int i=1; i<v.size(); i++)
{
temp = v[i-1];
v[i-1] = v[i] - temp;
if(v[i-1] < 0) v[i-1]*=-1;
}
for(int i=0; i<v.size()-sss; i++)
{
cout << v[i] << " ";
}
sss++;
cout << endl;
}
}
#include <iostream>
#include <cstring>
#include <iomanip>
using namespace std;
int main()
{
int list[10];
int diff;
int a ;
int b;
cout << "List" << endl;
for(int i=0;i<10;i++)
{
cin >> list[i];
}
cout << "Difference: ";
cin >> diff;
for (int i = 0; i<list[i];i++)
{
a = list[i];
b = list[i+1];
if(b-a == diff)
{
cout<<"Pair Found"<<"(" << a <<","<< b << ")"<<endl;
}
else
{
cout<<"No Pair Found"<<endl;
}
}
}
import java.util.*;
import java.io.*;
import java.math.BigInteger;
class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int cases = Integer.parseInt(br.readLine());
for(int i=0; i<cases; i++){
String line = br.readLine();
if(line.contains("+")) {
int pos = line.indexOf("+");
double num1 = Double.parseDouble(line.substring(0, pos));
double num2 = Double.parseDouble(line.substring(pos+1));
System.out.printf("%.2f\n", (num1+num2));
}
if(line.contains("-")) {
int pos = line.indexOf("-");
double num1 = Double.parseDouble(line.substring(0, pos));
double num2 = Double.parseDouble(line.substring(pos+1));
System.out.printf("%.2f\n", (num1-num2));
}
if(line.contains("*")) {
int pos = line.indexOf("*");
double num1 = Double.parseDouble(line.substring(0, pos));
double num2 = Double.parseDouble(line.substring(pos+1));
System.out.printf("%.2f\n", (num1*num2));
}
if(line.contains("/")) {
int pos = line.indexOf("/");
double num1 = Double.parseDouble(line.substring(0, pos));
double num2 = Double.parseDouble(line.substring(pos+1));
if(num2 == 0) System.out.println("NaN");
else System.out.printf("%.2f\n", (num1/num2));
}
}
}
}
x = list(map(int, input().strip().split(' ')))
y = int(input())
z = [y + i for i in x]
p = []
for k in z:
if k in x:
p.append([k - y, k])
if len(p) == 0:
print("No Pair Found")
else:
print("Pair Found: " + ", ".join(["(%d, %d)" % (a, b) for a, b in sorted(p)]))
#include<iostream>
#include<sstream>
using namespace std;
int main()
{
int num[10];
string input;
getline(cin,input);
stringstream ss(input);
int counter = 0;
while(ss>>num[counter])
{
counter++;
}
int diff;
cin>>diff;
int a,b;
bool found =true;
bool first = true;
for(int i=0;i<counter-1;i++)
{
a=num[i+1];
b=num[i];
if(a-b==diff){
if(found)
cout<<"Pair Found: ";
found = false;
if(!first)cout<<", ";
cout<<"("<<b<<", "<<a<<")";
first=false;
}
}
if(found)
{
cout<<"No Pair Found";
}
return 0;
}
x = list(map(int, input().strip().split(' ')))
y = int(input())
# z = [y + i for i in x]
# p = []
# for k in z:
# if k in x:
# p.append([k - y, k])
p = []
for i in x:
if (i + y) in x[:i] + x[i:]:
p.append((i, i + y))
if len(p) == 0:
print("No Pair Found")
else:
print("Pair Found: " + ", ".join(["(%d, %d)" % (a, b) for a, b in sorted(p)]))
#include<iostream>
#include<sstream>
using namespace std;
int main()
{
int num[10];
int counter = 0;
do
{
string input;
counter = 0;
getline(cin,input);
stringstream ss(input);
while(ss>>num[counter])
{
counter++;
}
}while(counter<2||counter>10);
int diff;
cin>>diff;
int a,b;
bool found =true;
bool first = true;
for(int i=0;i<counter-1;i++)
{
a=num[i+1];
b=num[i];
if(a-b==diff){
if(found)
cout<<"Pair Found: ";
found = false;
if(!first)cout<<", ";
cout<<"("<<b<<", "<<a<<")";
first=false;
}
}
if(found)
{
cout<<"No Pair Found";
}
return 0;
}
#include <iostream>
using namespace std;
int main()
{
float a, b, ans;
int t;
char o;
cout<<"Enter number of test cases: ";
cin>>t;
if(t>0 && t<=100)
{
for(int i=0; i<t; i++)
{
ans=0;
cout<<"Enter number A: ";
cin>>a;
cout<<"Enter number B: ";
cin>>b;
cout<<"Enter operation: (+, -, *, /) : ";
cin>>o;
if(o == '+')
{
ans = a + b;
}
else if(o == '-')
{
ans = a - b;
}
else if(o == '*')
{
ans = a * b;
}
else if(o == '/')
{
ans = a / b;
}
else
cout<<"\nNaN";
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<ans<<endl;
}
}
return 0;
}
//package prosolve_im26c4u;
import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.util.regex.Pattern;
public class Main {
// public static void main(String[] args) throws IOException{
// BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// int numCases = Integer.parseInt(br.readLine());
//
// for(int i=0; i< numCases; i++){
// TreeMap<String, Integer> map = new TreeMap<>();
// int numWords = Integer.parseInt(br.readLine());
// for(int j=0; j<numWords; j++){
// String[] a = br.readLine().split("\t");
// if(!map.containsKey(a[0])){
// map.put(a[0], 0);
// }
// map.put(a[0], map.get(a[0])+1);
// }
//
// for(Map.Entry<String, Integer> m : map.entrySet()){
// System.out.println(m.getValue()+"\t"+m.getKey());
//
// }
// if(i!=numCases-1) System.out.println("");
// }
// }
// public static void main(String arg[])throws IOException{
// BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// String s = br.readLine();
// String ans = s.replaceAll("[^A-Za-z]","");
// System.out.println(ans);
// }
// public static boolean composite[] = new boolean[10001];
// public static int primeF[] = new int[10001];
// public static void soe(int up){
// int sqrt = (int)Math.sqrt(up);
// for(int i=2;i<=sqrt;i++){
// if(!composite[i]){
// for(int j=i*i;j<=up;j+=i){
//// System.out.println(j);
// composite[j] = true;
// if(primeF[j]==0){
// primeF[j] = i;
//// System.out.println(primeF[j]);
// }else{
// primeF[j] = Math.min(i,primeF[j]);
// }
// }
// }
// }
// }
// public static void main (String args[]) throws IOException{
// String input = "a.in";
// String output = "a.out";
// boolean file = false;
// BufferedReader br;
// if(file)
// br = new BufferedReader(new FileReader(input));
// else
// br = new BufferedReader(new InputStreamReader(System.in));
// PrintWriter pr;
// if(file){
// pr = new PrintWriter(new FileWriter(output));
// }else{
// pr = new PrintWriter(System.out);
// }
// soe(10000);
//
// int T = Integer.parseInt(br.readLine());
// for(int i=0;i<T;i++){
// int N = Integer.parseInt(br.readLine());
// if(primeF[N]==0){
// System.out.println("Prime");
// }else{
// System.out.println(primeF[N]);
// }
// }
//
// pr.close();
// }
// public static void main (String args[]) throws IOException{
// String input = "a.in";
// String output = "a.out";
// boolean file = false;
// BufferedReader br;
// if(file)
// br = new BufferedReader(new FileReader(input));
// else
// br = new BufferedReader(new InputStreamReader(System.in));
// PrintWriter pr;
// if(file){
// pr = new PrintWriter(new FileWriter(output));
// }else{
// pr = new PrintWriter(System.out);
// }
// int N = Integer.parseInt(br.readLine());
// BigInteger b[] = new BigInteger[1001];
// b[0] = BigInteger.ONE;
// b[1] = new BigInteger("2");
// for(int i=2;i<=1000;i++){
// b[i] = b[i-1].add(b[i-2]);
// }
// for(int i=0;i<N;i++){
// int t = Integer.parseInt(br.readLine());
// System.out.println(b[t]);
// }
// pr.close();
// }
public static void main (String args[]) throws IOException{
String input = "a.in";
String output = "a.out";
boolean file = false;
BufferedReader br;
if(file)
br = new BufferedReader(new FileReader(input));
else
br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pr;
if(file){
pr = new PrintWriter(new FileWriter(output));
}else{
pr = new PrintWriter(System.out);
}
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
long b = Long.parseLong(st.nextToken());
long total = 0;
long count = 0;
st = new StringTokenizer(br.readLine());
for(int i=0;i<n;i++){
long v = Long.parseLong(st.nextToken());
if(v==0){
long c = total/b;
if(total%b!=0){
c++;
}
count += c;
total = 0;
}else{
total += v;
}
}
long c = total/b;
if(total%b!=0){
c++;
}
count += c;
System.out.println(count);
pr.close();
}
}
nums = [int(x) for x in input().split()]
nnums = len(nums)
list1 = []
while(nnums > 0):
list2 = []
for i in range(len(nums)-1):
list2.append(abs(nums[i+1] - nums[i]))
list1.append(list2)
nums = list2
nnums= nnums-1
for i in list1:
print("{}".format([x for x in i])[1:-1].replace(",",""))
/**
* Write a description of class g2 here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.util.*;
import java.math.*;
public class g2
{
public static void main (String args[])
{
Scanner inp = new Scanner(System.in);
System.out.print(" ");
int i, T = inp.nextInt(), num, arr[] = new int[T];
for (i=0; i<T; i++)
{
arr[i] = inp.nextInt();
}
while (T!=0)
{
for (i=0; i<T-1; i++)
{
num = arr[i+1] - arr[i];
if (num<0)
num=-num;;
arr[i] = num;
System.out.print(num);
System.out.print(" ");
}
System.out.print("\n");
T--;
}
}
}
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
int n, b;
int arr[200200];
int main() {
long long ans = 0, rem = 0;
scanf("%d%d", &n, &b);
for (int i = 0; i < n; ++i)
scanf("%d", &arr[i]);
for (int i = 0; i < n; ++i) {
//cout << rem << " " << arr[i] << endl;
if (rem + arr[i] <= b && rem > 0) {
++ans;
rem = 0;
continue;
}
arr[i] += rem;
ans += arr[i] / b;
rem = arr[i] % b;
}
if (rem) ++ans;
cout << ans << endl;
return 0;
}
#include <iostream>
#include <string>
using namespace std;
int main()
{
int T;
cin>>T;
float A,B,C;
char O;
for(int b=0; b<T; b++)
{
cin>>A;
cin>>O;
cin>>B;
if (B==0)
{
cout<<"NaN"<<endl;
}
else
{
if (O == '+')
{
C=A+B;
}
else if (O == '-')
{
C=A-B;
}
else if (O == '*')
{
C=A*B;
}
else if (O == '/')
{
C=A/B;
}
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<C<<endl;
}
}
return 0;
}
wrong-answer
) (Time Submission : 12:09) (Problem :D - Smart Garbage Disposal System
)s = 0
r = 0
n, b = map(int, input().strip().split(" "))
G = [int(x) for x in input().strip().split(" ")]
for i in range(n):
g = G[i]
g += r
s += g //b
r = g % b
if n-1-i == 0 and r > 0:
s +=1
print(s)
import java.util.*;
public class G
{
public static void main(String []args){
Scanner input = new Scanner(System.in);
String lines = input.nextLine();
String arr[] = lines.split(" ");
int arrL = arr.length;
for(int y=0; y<arrL-1; y++){
String arr2[] = lines.split(" ");
for(int x=0; x<arr2.length-1; x++){
int a = Integer.parseInt(arr2[x+1]) - Integer.parseInt(arr2[x]);
arr2[x] = String.valueOf(Math.abs(a));
}
lines = "";
for(int z=0; z<arr2.length-1; z++){
lines += arr2[z]+" ";
}
System.out.println(lines);
}
}
}
x = list(map(int, input().strip().split(' ')))
y = int(input())
# z = [y + i for i in x]
# p = []
# for k in z:
# if k in x:
# p.append([k - y, k])
p = []
for i in x:
if (i + y) in x[:i] + x[i:]:
p.append(sorted([i, i + y]))
if len(p) == 0:
print("No Pair Found")
else:
print("Pair Found: " + ", ".join(["(%d, %d)" % (a, b) for a, b in sorted(p)]))
import java.math.BigInteger;
import java.util.*;
public class i {
public static void main(String[] args) {
ArrayList alist = new ArrayList();
ArrayList blist = new ArrayList();
Scanner in = new Scanner(System.in);
for (int cases = in.nextInt(); cases > 0; cases--) {
int a = in.nextInt();
if (isPrime(a)) {
System.out.println("Prime");
} else {
for (int i = 2; i <= Math.sqrt(a); i++) {
if (a % i == 0) {
System.out.println(i);
break;
}
}
}
}
}
public static boolean isPrime(int a) {
if (a <= 1)
return false;
for (int i = 2; i <= Math.sqrt(a); i++) {
if (a % i == 0)
return false;
}
return true;
}
}
���4O
,- ./
0
12
)3
45 .6
)7
89:;<init>()VCodeLineNumberTableLocalVariableTablethisLd;main([Ljava/lang/String;)ViIargs[Ljava/lang/String;scanLjava/util/Scanner;lineLjava/lang/String;worddaycapacityscan2daysgabtotalresultcount
StackMapTable<
SourceFiled.javajava/util/Scanner=>?@AB\W+CDEFGHIJKLMNdjava/lang/Objectjava/lang/Stringjava/lang/SysteminLjava/io/InputStream;(Ljava/io/InputStream;)VnextLine()Ljava/lang/String;split'(Ljava/lang/String;)[Ljava/lang/String;java/lang/IntegerparseInt(Ljava/lang/String;)IoutLjava/io/PrintStream;valueOf(I)Ljava/lang/String;java/io/PrintStreamprintln(Ljava/lang/String;)V!
/*�� ���Y��L+�M,�N-2�6-2�6�Y��:�M,�:66 �� 2�`6� ���6 6
�
h6 �
���
d�
��N
'3
9ADO\behov|�zG �zsk 'c!3W"AI#DF$e%% h"&
'(�G
()((��*+
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] inputs = br.readLine().split(" ");
Map<Integer, Integer> m = new HashMap<>();
for (int i = Integer.parseInt(inputs[0]); i --> 0;){
String[] s = br.readLine().split(" ");
m.put(Integer.parseInt(s[0]), Integer.parseInt(s[1]));
}
List<Integer> k = new ArrayList<>(m.keySet());
Collections.sort(k);
for (int i = Integer.parseInt(inputs[1]); i --> 0;){
int index = 0;
int t = Integer.parseInt(br.readLine());
for(int j = 0; j < k.size(); j++){
index = j;
if(k.get(j) > t){
index --;
break;
}
}
if(index == -1) {
System.out.printf("%d %d %d\n" , -1, -1, k.get(0));
}else{
System.out.printf("%d %d %d\n" , m.get(k.get(index)), k.get(index), (index + 1 == k.size())? -1 : k.get(index +1));
}
}
}
}
import java.util.*;
import java.io.*;
class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String text = "";
while((text = br.readLine())!=null && !text.isEmpty()){
int diff = Integer.parseInt(br.readLine());
ArrayList<String> numbers = new ArrayList<>();
String[] arr = text.split(" ");
int[] arrInt = new int[arr.length];
for(int i=0; i<arr.length; i++){
arrInt[i] = Integer.parseInt(arr[i]);
}
Arrays.sort(arrInt);
for(int i=0; i<arrInt.length-1; i++){
for(int j=i+1; j<arrInt.length; j++){
int max = Math.max(arrInt[i], arrInt[j]);
int min = Math.min(arrInt[i], arrInt[j]);
if(max - min == diff){
numbers.add(String.format("(%d,%d)", min, max));
}
}
}
if(numbers.isEmpty()) System.out.println("No Pair Found");
else{
System.out.print("Pair Found: ");
for(int i=0; i<numbers.size()-1; i++){
System.out.print(numbers.get(i) + ",");
}
System.out.println(numbers.get(numbers.size()-1));
}
}
}
}
#include<iostream>
using namespace std;
int main()
{
int t;
int b = 0;
cin>>t;
int arr[t];
for (int m = 0; m < t; m++)
{
cin>>arr[m];
}
cout<<"\n";
for (int m = 0; m < t; m++)
{
if ( arr[m] == 0)
{
cout<<"0";
break;
}
else
{
for ( int i = 2; i < 10; i++)
{
if (( arr[m] % i == 0 ) && ( arr[m]!=i ))
{
b = i;
break;
}
}
if ( b == 0)
{
cout<<"Prime";
cout<<"\n";
}
else
{
cout<<b;
cout<<"\n";
}
}
}
return 0;
}
import java.util.*;
class a{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
String inputT = sc.nextLine();
int inputN = Integer.parseInt(sc.nextLine());
String[] s = inputT.split(" ");
Integer[] arr = new Integer[s.length];
for(int i=0; i<s.length; i++){
arr[i] = Integer.parseInt(s[i]);
}
String output = "";
boolean found = false;
boolean coma = false;
for(int i = 0; i<arr.length; i++){
int a = arr[i];
for(int j=0 ; j<arr.length; j++){
int b = arr[j];
if(b > a && (b-a==inputN)){
coma = true;
if(coma && found) output += ", ";
if(output.indexOf("("+a+","+b+")") != 0)
output += "("+a+","+b+")";
found = true;
}
coma = false;
}
}
if(found) System.out.println("\nPair Found: "+output);
else System.out.println("\nNo Pair Found!");
}
}
import java.util.*;
import java.io.*;
class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String text = "";
while((text = br.readLine())!=null && !text.isEmpty()){
int diff = Integer.parseInt(br.readLine());
ArrayList<String> numbers = new ArrayList<>();
String[] arr = text.split(" ");
int[] arrInt = new int[arr.length];
for(int i=0; i<arr.length; i++){
arrInt[i] = Integer.parseInt(arr[i]);
}
Arrays.sort(arrInt);
for(int i=0; i<arrInt.length-1; i++){
for(int j=i+1; j<arrInt.length; j++){
int max = Math.max(arrInt[i], arrInt[j]);
int min = Math.min(arrInt[i], arrInt[j]);
if(max - min == diff){
numbers.add(String.format("(%d,%d)", min, max));
}
}
}
if(numbers.isEmpty()) System.out.println("No Pair Found");
else{
System.out.print("Pair Found:");
for(int i=0; i<numbers.size()-1; i++){
System.out.print(numbers.get(i) + ",");
}
System.out.println(numbers.get(numbers.size()-1));
}
}
}
}
/**
* Write a description of class g2 here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.util.*;
import java.math.*;
public class g2
{
public static void main (String args[])
{
Scanner inp = new Scanner(System.in);
int i, T = inp.nextInt(), num, arr[] = new int[T];
for (i=0; i<T; i++)
{
arr[i] = inp.nextInt();
}
while (T!=0)
{
for (i=0; i<T-1; i++)
{
num = arr[i+1] - arr[i];
if (num<0)
num=-num;;
arr[i] = num;
System.out.print(num);
System.out.print(" ");
}
System.out.print("\n");
T--;
}
}
}
tc = int(input())
if tc >= 1 and tc <= 50:
for i in range(tc):
prime = int(input())
str1 = "Prime"
if prime >= 2 and prime <=10000:
for x in range(2, prime, 1):
if prime % x == 0:
str1 = str(x)
break
print(str1)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public class C {
// public static void main(String[] args) throws IOException {
// BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// StringBuilder sb = new StringBuilder();
// int T = Integer.parseInt(br.readLine());
// cache[0] = 0;
// cache[1] = 2;
// cache[2] = 3;
// while(T>0){
// sb.append(solve(Integer.parseInt(br.readLine())));
// sb.append("\n");
// T--;
// }
// System.out.println(sb.toString());
// }
// public static int solve(int N){
// if(cache[N]!=0){
// return cache[N];
// }
// else{
// return solve(N-1)+solve(N-2);
// }
// }static int[] cache = new int[1001];
public static void main(String[] args){
Scanner input =new Scanner(System.in);
int n = input.nextInt();
while (n>0){
int x= input.nextInt();
if(x==1){
System.out.println(2);
}
else{
System.out.println((int)(x+Math.pow(2,x-2)));
}
}
}
}
#include<iostream>
using namespace std;
int main()
{
int a;
cin >> a;
for(int b = 0; b < a; b++)
{
int num;
cin >> num;
int total = 1 + num;
for(int c = 2; c < num; c++)
{
int d = c;
while((num - d) > 0)
{
total = total + (num - d);
d++;
}
}
cout << total << endl;
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public class C {
// public static void main(String[] args) throws IOException {
// BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// StringBuilder sb = new StringBuilder();
// int T = Integer.parseInt(br.readLine());
// cache[0] = 0;
// cache[1] = 2;
// cache[2] = 3;
// while(T>0){
// sb.append(solve(Integer.parseInt(br.readLine())));
// sb.append("\n");
// T--;
// }
// System.out.println(sb.toString());
// }
// public static int solve(int N){
// if(cache[N]!=0){
// return cache[N];
// }
// else{
// return solve(N-1)+solve(N-2);
// }
// }static int[] cache = new int[1001];
public static void main(String[] args){
Scanner input =new Scanner(System.in);
int n = input.nextInt();
while (n>0){
int x= input.nextInt();
if(x==1){
System.out.println(2);
}
else{
System.out.println((int)(x+Math.pow(2,x-2)));
}
n--;
}
}
}
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int n = 0;
cin >> n;
for(int t = 0; t < n; t++)
{
float x, y;
char z;
cin >> x >> z >> y;
cout << fixed << showpoint << setprecision(2);
if(z == '+')
cout << x + y << endl;
else if(z == '-')
cout << x - y << endl;
else if(z == '*')
cout << x * y << endl;
else if(z == '/')
{
if(y == 0)
cout << "NaN" << endl;
else
cout << x / y << endl;
}
}
}
#include<iostream>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
int garbage= 0;
int day;
for(int i=0;i<a;i++)
{
cin>>day;
garbage +=day;
}
if((double)garbage/b>(int)garbage/b)
{
cout<<garbage/b + 1;
}
else
cout<<garbage/b;
return 0;
}
#include <iostream>
using namespace std;
bool isPrime(int a)
{
for(int i=2; i<a; i++)
{
if(a%i == 0)
return false;
}
return true;
}
void findFactor(int a)
{
for(int i=2; i<a; i++)
{
if(isPrime(i) && a%i == 0)
{
cout << i << endl;
break;
}
}
}
void prime(int a)
{
bool primeee = isPrime(a);
if(primeee)
cout << "Prime" << endl;
else
findFactor(a);
}
int main()
{
int t;
cin >> t;
while(t--)
{
int a;
cin >> a;
prime(a);
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public class C {
static int[] cache = new int[1001];
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int T = Integer.parseInt(br.readLine());
cache[0] = 0;
cache[1] = 2;
cache[2] = 3;
while(T>0){
sb.append(solve(Integer.parseInt(br.readLine())));
sb.append("\n");
T--;
}
System.out.println(sb.toString());
}
public static int solve(int N) {
if (cache[N] != 0) {
return cache[N];
} else {
return cache[N]=solve(N - 1) + solve(N - 2);
}
}
}
#include <iostream>
#include <cstring>
#include <iomanip>
using namespace std;
int main()
{
int list[10];
int diff;
int a ;
int b;
cout << "List" << endl;
for(int i=0;i<10;i++)
{
cin >> list[i];
}
cout << "Difference: ";
cin >> diff;
for (int i = 0; i<list[10];i++)
{
a = list[i];
b = list[i+1];
if(b-a == diff)
{
cout<<"Pair Found"<<"(" << a <<","<< b << ")"<<endl;
}
}
}
#include <iostream>
#include<conio.h>
using namespace std;
int main()
{
int test;
float first, second;
char operators;
float result;
cout<<"Enter number of test cases : ";
cin>>test;
while(test != 0)
{
cout<<"\n\nEnter expression : (NUMBER OPERAND NUMBER) "<<endl;
cin>>first>>operators>>second;
switch(operators)
{
case '+' : result = first + second;
break;
case '-' : result = first - second;
break;
case '*' : result = first * second;
break;
case '/' : if(second != 0.0)
result = first/second;
else
cout<<"NaN";
break;
default : cout<<operators<<"is unrecognised operation"<<endl;
return 0;
}
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<"\n"<<result;
test--;
}
return 0;
}
#include <iostream>
#include <cmath>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main() {
int n;
double b,sum=0;
cin >> n >>b;
for(int i=0; i<n; i++){
double a;
cin >> a;
sum+=a;
}
int answer = ceil(sum/b);
cout << answer << endl;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
double ex[n][2];
double x_=0,y_=0;
for(int i=0;i<n;i++){
cin>>ex[i][0]>>ex[i][1];
x_+=ex[i][0];y_+=ex[i][1];
// cout<<ex[i][0]<<" "<<ex[i][1]<<endl;
}
x_/=n;y_/=n;
double up=0,dw=0;
for(int i=0;i<n;i++){
up+=(ex[i][0]-x_)*(ex[i][1]-y_);
dw+=(ex[i][0]-x_)*(ex[i][0]-x_);
}
double bt=up/dw,al=y_-bt*x_;
// cout<<bt<<" "<<al<<endl;
printf("%.4f %.4f\n",bt,al);
int t;
cin>>t;
while(t--){
double x;cin>>x;
double ans=al+bt*x;
printf("%.4f\n",ans);
}
}
#include <iostream>
#include <string>
using namespace std;
int main()
{
int T;
cin>>T;
float A,B,C[T];
char O;
for(int b=0; b<T; b++)
{
cin>>A;
cin>>O;
cin>>B;
if (B==0)
{
C[b] = -999;
}
else
{
if (O == '+')
{
C[b]=A+B;
}
else if (O == '-')
{
C[b]=A-B;
}
else if (O == '*')
{
C[b]=A*B;
}
else if (O == '/')
{
C[b]=A/B;
}
}
}
for(int b=0; b<T; b++)
{
if(C[b] == -999)
{cout<<"NaN"<<endl;}
else
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<C[b]<<endl;
}
}
return 0;
}
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int T;
cin>>T;
if (T >= 1 && T <= 100)
{
float a,b,ans;
char o;
while(T != 0)
{
cin>>a>>o>>b;
if (a>=0 && b>= 0 && a <= 10000 && b <= 10000)
{
if (o == '+')
{
ans = a+b;
cout<<fixed<<setprecision(2)<<ans<<endl;
}
else if (o == '-')
{
ans = a-b;
cout<<fixed<<setprecision(2)<<ans<<endl;
}
else if (o == '*')
{
ans = a*b;
cout<<fixed<<setprecision(2)<<ans<<endl;
}
else if (o == '/')
{
if (b == 0) cout<<"NaN"<<endl;
else {
ans = a/b;
cout<<fixed<<setprecision(2)<<ans<<endl;
}
}
else
{
cout<<"NaN"<<endl;
}
}
else cout<<"NaN"<<endl;
T--;
}
}
else cout<<"NaN"<<endl;
}
import math
ngarbage, days = input().split()
ngarbage = int(ngarbage)
days = int(days)
list1= [int(x) for x in input().split()]
print(math.ceil(sum(list1)/days))
#include <iostream>
#include <cmath>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main() {
long long n, b;
long long sum=0;
cin >> n >>b;
for(int i=0; i<n; i++){
long long a;
cin >> a;
sum+=a;
}
long long answer = ceil((1.0*sum)/(b*1.0));
cout << answer << endl;
return 0;
}
#include<iostream>
#include <iomanip>
using namespace std;
int main()
{
int T;
float A, B;
char O;
cin>>T;
if (T > 1 && T <= 100)
{
for (int i = 0; i < T; i++)
{
cin>>A>>O>>B;
if (A >= 0 && A <= 10000 && B >= 0 && B <= 10000)
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
if (O == '+')
cout<<(A + B);
else if (O == '-')
cout<<(A - B);
else if (O == '*')
cout<<(A * B);
else if (O == '/')
{
if (B == 0)
cout<<"NaN";
else
cout<<(A / B);
}
}
else
cout<<"NaN";
}
}
else
cout<<"T is below 0 or above 100";
return 0;
}
import java.util.*;
import java.text.*;
public class CALC {
public static void main(String args[]){
Scanner s = new Scanner (System.in);
Scanner n = new Scanner (System.in).useDelimiter("");
DecimalFormat df = new DecimalFormat("0.00");
int num=0;
int i=0;
num = s.nextInt();
String O=" ";
double A=0.00, B=0.00;
double ans=0.00;
for(i=0; i<num; i++)
{
A= s.nextDouble();
O= n.nextLine();
B= s.nextDouble();
if(O.equals("+"))
{
ans = A + B;
}
else if(O.equals("-"))
{
ans = A - B;
}
else if(O.equals("*"))
{
ans = A * B;
}
else if(O.equals("/"))
{
ans = A / B;
}
else
{
System.out.println("NaN");
}
System.out.print(df.format(ans));
}}}
import java.util.*;
class a{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
String inputT = sc.nextLine();
int inputN = Integer.parseInt(sc.nextLine());
String[] s = inputT.split(" ");
Integer[] arr = new Integer[s.length];
for(int i=0; i<s.length; i++){
arr[i] = Integer.parseInt(s[i]);
}
String output = "";
boolean found = false;
boolean coma = false;
for(int i = 0; i<arr.length; i++){
int a = arr[i];
for(int j=0 ; j<arr.length; j++){
int b = arr[j];
if(b > a && (b-a==inputN)){
coma = true;
if(!output.contains("("+a+","+b+")")){
if(coma && found) output += ", ";
output += "("+a+","+b+")";
}
found = true;
}
coma = false;
}
}
if(found) System.out.println("\nPair Found: "+output);
else System.out.println("\nNo Pair Found");
}
}
#include <bits/stdc++.h>
using namespace std;
int main(){
int sol[1001];
sol[1]=2;
sol[2]=3;
for(int i=3;i<=1000;i++)
sol[i]=sol[i-2]+sol[i-1];
int t;cin>>t;
while(t--){
int c;cin>>c;
cout<<sol[c]<<endl;
}
}
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <cctype>
#include <iomanip>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int prime(int input)
{
//prime
if(input == 1 || input== 2 || input == 5 || ( input%2!=0 && input%3!=0 && input%5!=0))
return 0;
else
{
int hold[]={2,3,4,5,6,7,8,9};
for(int i=0;i <= sizeof(hold);i++)
{
if(input%hold[i] == 0)
{
return hold[i];
}
}
}
}
int main(int argc, char** argv) {
int loop, input[20];
cin >> loop;
for(int i=0;i<loop;i++)
{
cin >> input[i];
}
for(int i = 0;i<loop;i++)
{
int out = prime(input[i]);
if (out == 0)
cout << "Prime\n";
else
cout << out << endl;
}
return 0;
}
#include<iostream>
#include<sstream>
using namespace std;
int main()
{
int num[10];
int counter = 0;
do
{
string input;
counter = 0;
getline(cin,input);
stringstream ss(input);
while(ss>>num[counter])
{
counter++;
}
}while(counter<2||counter>10);
int diff;
cin>>diff;
int a,b;
bool found =true;
bool first = true;
for(int i=0;i<counter;i++)
{
for(int j=0;j<counter;j++)
{
if(i==j)continue;
a=num[i];
b=num[j];
if(a-b==diff&&b<=a){
if(found)
cout<<"Pair Found: ";
found = false;
if(!first)cout<<", ";
cout<<"("<<b<<", "<<a<<")";
first=false;
}
}
}
if(found)
{
cout<<"No Pair Found";
}
return 0;
}
def read():
return map(int, input().strip().split(" "))
n, q = read()
r = []
for i in range(n):
t, x = read()
r.append((t,x))
r = sorted(r, key=lambda k: k[0])
for i in range(q):
a = int(input())
if r[0][0] > a:
print(-1,-1,r[0][0])
elif r[-1][0] < a:
print(r[-1][1], r[-1][0], -1)
else:
for j in range(n):
if r[j+1][0] > a:
print(r[j][1], r[j][0], r[j+1][0])
break
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigDecimal;
import java.util.StringTokenizer;
public class D {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
BigDecimal b = new BigDecimal(st.nextToken());
BigDecimal sum = BigDecimal.ZERO;
st = new StringTokenizer(br.readLine());
for(int i =0;i<n;i++){
sum = sum.add(new BigDecimal(st.nextToken()));
}
BigDecimal bags = sum.divide(b);
System.out.println((int)Math.ceil(bags.doubleValue()));
}
}
#include <iostream>
#include <cmath>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main() {
long long n, b;
long long sum=0;
cin >> n >>b;
for(int i=0; i<n; i++){
long long a;
cin >> a;
sum+=a;
}
long long answer = ceil((1.0*sum)/(b*1.0));
cout << answer;
return 0;
}
#BlueJ package file
package.editor.height=400
package.editor.width=560
package.editor.x=549
package.editor.y=46
package.numDependencies=0
package.numTargets=1
package.showExtends=true
package.showUses=true
target1.editor.height=524
target1.editor.width=626
target1.editor.x=106
target1.editor.y=362
target1.height=50
target1.name=pair
target1.showInterface=false
target1.type=ClassTarget
target1.width=80
target1.x=60
target1.y=10
import java.util.Scanner;
public class F {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
for (int i = 0; i < n; i++) {
double A = input.nextDouble();
double B = input.nextDouble();
if( A + B %2==0 ) {
System.out.println(A+ B);
}
else if( A - B %2==0 ) {
System.out.println(A- B);
}
else if( A * B %2==0 ) {
System.out.println(A* B);
}
else if( A / B %2==0 ) {
System.out.println(A/ B);
}
else
System.out.println();
}
}
}
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int n = 0;
cin >> n;
for(int t = 0; t < n; t++)
{
float x, y, total;
char z;
cin >> x >> z >> y;
if(z == '+')
total = x + y;
else if(z == '-')
total = x - y;
else if(z == '*')
total = x * y;
else if(z == '/')
total = x / y;
else
cout << "NaN" << endl;
cout << fixed << showpoint << setprecision(2);
cout << total << endl;
}
}
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <cctype>
#include <iomanip>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int prime(int input)
{
//prime
if(input == 1 || input== 2 || input == 5 || ( input%2!=0 && input%3!=0 && input%5!=0))
return 0;
else
{
int hold[]={2,3,4,5,6,7,8,9};
for(int i=0;i <8;i++)
{
if(input%hold[i] == 0)
{
return hold[i];
}
}
}
}
int main(int argc, char** argv) {
int loop, input[20];
cin >> loop;
for(int i=0;i<loop;i++)
{
cin >> input[i];
}
for(int i = 0;i<loop;i++)
{
int out = prime(input[i]);
if (out == 0)
cout << "Prime\n";
else
cout << out << endl;
}
return 0;
}
string = input()
num = string.split(' ')
st = list()
d = int(input())
k = len(num)
while k != 1:
for i in range(k-1):
t = int(num[i]) - int(num[i+1])
t = abs(t)
if t == d:
st.append('(' +str(min(int(num[i]),int(num[i+1])))+','+ str(max(int(num[i]),int(num[i+1]))) + ')')
k = k - 1
st.reverse()
flag = False
empty = []
if st != empty:
last = st[len(st)-1]
print('Pair Found: ',end='')
for i in st:
if i == last:
print(i,end='')
else:
print(i,end=', ')
flag = True
if not flag:
print("No Pair Found")
import java.util.*;
import java.io.*;
import java.math.BigInteger;
class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int size = Integer.parseInt(br.readLine());
double[] x = new double[size];
double[] y = new double[size];
double X = 0;
double Y = 0;
for(int i=0; i<size; i++){
String[] tmp = br.readLine().split(" ");
x[i] = Double.parseDouble(tmp[0]);
y[i] = Double.parseDouble(tmp[1]);
X += x[i];
Y += y[i];
}
X /= size;
Y /= size;
double sum1 = 0, sum2 = 0;
for(int i=0; i<size; i++){
sum1 += ((x[i]-X) * (y[i]-Y));
sum2 += Math.pow(x[i]-X, 2);
}
double b = sum1/sum2;
double a = Y - (b*X);
System.out.printf("%.4f %.4f\n", b, a);
int cases = Integer.parseInt(br.readLine());
for(int i=0; i<cases; i++){
double num = Double.parseDouble(br.readLine());
System.out.printf("%.4f\n", (b*num+a));
}
System.out.println("");
}
}
import math
while True:
try:
line1 = input().split()
line2 = input().split()
s = 0
remain = 0
for i in range(len(line2)):
n = int(line2[i])
n += remain
if i != len(line2) - 1:
remain = n % int(line1[1])
s += n // int(line1[1])
else:
s += math.ceil(n / int(line1[1]))
# print(s, remain)
print(s)
except Exception as e:
# print(e)
break
#include<iostream>
using namespace std;
long long int memo[101000];
long long int n;
long long int fib(long long int n){
if(n==1||n==2)
return 1;
if(memo[n]!=0)
return memo[n];
return memo[n] = fib(n-1)+fib(n-2);
}
int main(){
int cases = 0;
cin>>cases;
for(int x=0; x<cases; x++){
cin>>n;
long long int ans = fib(n+2);
cout<<ans<<endl;
}
}
def get_answer(data, timestamp, a):
try:
index = timestamp.index(a)
except:
index = -1
if index != -1: # exact case
prev = data[timestamp[index]]
if index + 1 >= len(timestamp):
next = -1
else:
next = timestamp[index + 1]
print('{} {} {}'.format(prev, a, next))
else:
low = 0
high = len(timestamp) - 1
if timestamp[-1] < a:
print('{} {} {}'.format(data[timestamp[-1]], timestamp[-1], -1))
elif timestamp[0] > a:
print('-1 -1 {}'.format(timestamp[0]))
else:
while True:
mid = (low + high) // 2
midval = timestamp[mid]
# print('mid',mid,'midval', midval)
if midval > a:
high = mid
else:
low = mid
if low == high - 1:
break
# print('after', low, high)
prev_val = data[timestamp[low]]
prev_time = timestamp[low]
next_time = timestamp[high]
print('{} {} {}'.format(prev_val, prev_time, next_time))
n, q = [int(x) for x in input().split(' ')]
data = {}
for ni in range(n):
t, x = [int(c) for c in input().split(' ')]
data[t] = x
timestamp = data.keys()
timestamp = sorted(timestamp)
for qi in range(q):
a = int(input())
get_answer(data, timestamp, a)
import java.util.*;
class a{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
String inputT = sc.nextLine();
int inputN = Integer.parseInt(sc.nextLine());
String[] s = inputT.split(" ");
Integer[] arr = new Integer[s.length];
for(int i=0; i<s.length; i++){
arr[i] = Integer.parseInt(s[i]);
}
String output = "";
boolean found = false;
boolean coma = false;
for(int i = 0; i<arr.length; i++){
int a = arr[i];
for(int j=0 ; j<arr.length; j++){
int b = arr[j];
if(b > a && (b-a==inputN)){
coma = true;
if(!output.contains("("+a+", "+b+")")){
if(coma && found) output += ", ";
output += "("+a+", "+b+")";
}
found = true;
}
coma = false;
}
}
if(found) System.out.println("\nPair Found: "+output+"\n");
else System.out.println("\nNo Pair Found\n");
}
}
import java.util.*;
import java.io.*;
class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String text = "";
while((text = br.readLine())!=null && !text.isEmpty()){
int diff = Integer.parseInt(br.readLine());
ArrayList<String> numbers = new ArrayList<>();
String[] arr = text.split(" ");
int[] arrInt = new int[arr.length];
for(int i=0; i<arr.length; i++){
arrInt[i] = Integer.parseInt(arr[i]);
}
Arrays.sort(arrInt);
for(int i=0; i<arrInt.length-1; i++){
for(int j=i+1; j<arrInt.length; j++){
int max = Math.max(arrInt[i], arrInt[j]);
int min = Math.min(arrInt[i], arrInt[j]);
if(max - min == diff){
numbers.add(String.format("(%d, %d)", min, max));
}
}
}
if(numbers.isEmpty()) System.out.println("No Pair Found");
else{
System.out.print("Pair Found: ");
for(int i=0; i<numbers.size()-1; i++){
System.out.print(numbers.get(i) + ", ");
}
System.out.println(numbers.get(numbers.size()-1));
}
}
}
}
#include <iostream>
using namespace std;
void calc(float a, char o, float b)
{
if(o == '+')
{
printf("%.02f", a+b);
}
else if(o == '-')
{
printf("%.02f", a-b);
}
else if(o == '*')
{
printf("%.02f", a*b);
}
else if(o == '/')
{
printf("%.02f", a/b);
}
cout << endl;
}
int main()
{
int t;
cin >> t;
while(t--)
{
char o;
float a, b;
cin >> a >> o >> b;
calc(a,o,b);
}
}
sol=[0]*1001
sol[1]=2
sol[2]=3
for i in range(3,1001):
sol[i]=sol[i-2]+sol[i-1]
t=int(input())
for i in range(t):
x=int(input())
print(sol[x])
#include <iostream>
using namespace std;
int main()
{
int test;
float first, second;
char operators;
float result;
cout<<"Enter number of test cases : ";
cin>>test;
while(test != 0)
{
cout<<"\n\nEnter expression : (NUMBER OPERAND NUMBER) "<<endl;
cin>>first>>operators>>second;
switch(operators)
{
case '+' : result = first + second;
break;
case '-' : result = first - second;
break;
case '*' : result = first * second;
break;
case '/' : if(second != 0.0)
result = first/second;
else
cout<<"NaN";
break;
default : cout<<operators<<"is unrecognised operation"<<endl;
return 0;
}
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<"\n"<<result;
test--;
}
return 0;
}
x = list(map(int, input().strip().split(' ')))
y = int(input())
z = [y + i for i in x]
p = []
for k in z:
if k in x:
p.append((k - y, k))
if len(p) == 0:
print("No Pair Found")
else:
print("Pair Found: " + ", ".join(["(%d, %d)" % (a, b) for a, b in sorted(list(set(p)))]))
#include <iostream>
using namespace std;
void calc(float a, char o, float b)
{
if(o == '+')
{
printf("%.02f", a+b);
}
else if(o == '-')
{
printf("%.02f", a-b);
}
else if(o == '*')
{
printf("%.02f", a*b);
}
else if(o == '/')
{
if(b == 0)
cout << "NaN" << endl;
else
printf("%.02f", a/b);
}
cout << endl;
}
int main()
{
int t;
cin >> t;
while(t--)
{
char o;
float a, b;
cin >> a >> o >> b;
calc(a,o,b);
}
}
#include<iostream>
using namespace std;
int main()
{
int c,i,n;
bool isPrime = true;
cin>>c;
for(int t=1; t<=c; ++t)
{
cin>>n;
for(int i=2; i<=n/2; ++i)
{
if(n % i == 0)
{
isPrime = false;
break;
}
}
if (isPrime)
{
cout << "Prime\n";
}
else
{
if (n%2 == 0)
{
cout<<"2\n";
}
else if (n%5 == 0)
{
cout<<"5\n";
}
}
}
return 0;
}
#include<iostream>
using namespace std;
int main()
{
double A,B,operation;
char O;
cout<<"Enter two number :"<<endl;
cin>>A>>B;
cout<<"Enter operation (+,-,/,*):"<<endl;
cin>>O;
if(O=='+')
{
operation=A+B;
cout<<operation;
}
else if (O=='-')
{
operation=A-B;
cout<<operation;
}
else if(O=='*')
{
operation=A*B;
cout<<operation;
}
else if(O=='/')
{
operation=A/B;
cout<<operation;
}
else
{
cout<<"NaN";
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigDecimal;
import java.util.StringTokenizer;
public class D {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
long b = Long.parseLong(st.nextToken());
int num = 0;
st = new StringTokenizer(br.readLine());
long remain = 0;
for(int i =0;i<n;i++){
while(remain>=b){
remain-=b;
num++;
}
long nex = Long.parseLong(st.nextToken());
nex+=remain;
while(nex>=b){
nex-=b;
num++;
}
remain=nex;
}
if(remain!=0){
num++;
}
System.out.println(num);
}
}
#include <iostream>
using namespace std;
void calc(float a, char o, float b)
{
if(o == '+')
{
printf("%.02f", a+b);
}
else if(o == '-')
{
printf("%.02f", a-b);
}
else if(o == '*')
{
printf("%.02f", a*b);
}
else if(o == '/')
{
if(b == 0)
cout << "NaN";
else
printf("%.02f", a/b);
}
cout << endl;
}
int main()
{
int t;
cin >> t;
while(t--)
{
char o;
float a, b;
cin >> a >> o >> b;
calc(a,o,b);
}
}
#include <iostream>
using namespace std;
int main ()
{
bool isPrime=true;
int test;
cin>>test;
int notprime;
int n[test];
int count;
for(int j=0;j<test;j++){
cin>>n[j];
for(int i=2;i<=n[j]/2;++i){
count=0;
if(n[j]%i==0)
{
isPrime=false;
if(n[j]%2==0)
notprime=2;
else if(n[j]%3==0)
notprime=3;
else if(n[j]%5==0)
notprime=5;
else if(n[j]%7==0)
notprime=7;
}
}
if(isPrime)
cout<<"Prime"<<endl;
else
cout<<notprime<<endl;
}
}
#include <iostream>
using namespace std;
int main ()
{
bool isPrime=true;
int test;
cin>>test;
int notprime;
int n[test];
for(int j=0;j<test;j++){
cin>>n[j];
for(int i=2;i<=n[j]/2;++i){
if(n[j]%i==0)
{
isPrime=false;
if(n[j]%2==0)
notprime=2;
else if(n[j]%3==0)
notprime=3;
else if(n[j]%5==0)
notprime=5;
else if(n[j]%7==0)
notprime=7;
}
}
if(isPrime)
cout<<"Prime"<<endl;
else
cout<<notprime<<endl;
}
}
x = list(map(int, input().strip().split(' ')))
y = int(input())
z = [y + i for i in x]
p = []
for k in z:
if k in x:
p.append(tuple(sorted([k - y, k])))
if len(p) == 0:
print("No Pair Found")
else:
print("Pair Found: " + ", ".join(["(%d, %d)" % (a, b) for a, b in sorted(p)]))
print()
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigDecimal;
import java.util.StringTokenizer;
public class D {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
long b = Long.parseLong(st.nextToken());
int num = 0;
st = new StringTokenizer(br.readLine());
long remain = 0;
for(int i =0;i<n;i++){
if(remain>=b){
num+=remain/b;
remain = remain%b;
}
long nex = Long.parseLong(st.nextToken());
nex+=remain;
if(nex>=b){
num+=nex/b;
nex=nex%b;
}
remain=nex;
}
if(remain!=0){
num++;
}
System.out.println(num);
}
}
x = list(map(int, input().strip().split(' ')))
y = int(input())
z = [y + i for i in x]
p = []
for k in z:
if k in x:
p.append(tuple(sorted([k - y, k])))
if len(p) == 0:
print("No Pair Found")
else:
print("Pair Found: " + ", ".join(["(%d, %d)" % (a, b) for a, b in sorted(p)]))
x = list(map(int, input().strip().split(' ')))
y = int(input())
z = [y + i for i in x]
p = []
for k in z:
if k in x:
p.append(tuple(sorted([k - y, k])))
if len(p) == 0:
print("No Pair Found")
else:
print("Pair Found: " + ", ".join(["(%d, %d)" % (a, b) for a, b in sorted(list(set(p)))]))
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
int n, m;
char arr[110][110];
pii par[110][110];
int dist[110][110];
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int Dijkstra(int x, int y) {
memset(dist, 0x3f, sizeof dist);
dist[x][y] = 0;
priority_queue<node, vector<node>, greater<node> > pq;
pq.push(make_pair(0, make_pair(x, y)));
while (!pq.empty()) {
node me = pq.top();
//cout << me.F << " " << me.S.F << " " << me.S.S << endl;
pq.pop();
if (arr[me.S.F][me.S.S] == 'C')
return dist[me.S.F][me.S.S];
if (dist[me.S.F][me.S.S] < me.F)
continue;
for (int k = 0; k < 4; ++k) {
int X = me.S.F + dx[k];
int Y = me.S.S + dy[k];
if (X < 0 || X == n || Y < 0 || Y == m) continue;
if (arr[X][Y] == '#') continue;
int w = (arr[X][Y] == 'S'? 5 : 1);
if (dist[X][Y] <= dist[me.S.F][me.S.S] + w) continue;
dist[X][Y] = dist[me.S.F][me.S.S] + w;
par[X][Y] = make_pair(me.S.F, me.S.S);
pq.push(make_pair(dist[X][Y], make_pair(X, Y)));
}
}
return -1;
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j)
scanf(" %c", &arr[i][j]);
int cx = -1, cy = -1;
for (int i = 0 ; i < n; ++i)
for (int j = 0; j < m; ++j) {
if (arr[i][j] == 'D') {
Dijkstra(i, j);
}
if (arr[i][j] == 'C')
cx = i, cy = j;
}
string ans = "";
while (arr[cx][cy] != 'D') {
int nxtX = par[cx][cy].F;
int nxtY = par[cx][cy].S;
if (nxtY < cy) ans += "R";
if (nxtY > cy) ans += "L";
if (nxtX < cx) ans += "D";
if (nxtX > cx) ans += "U";
cx = nxtX;
cy = nxtY;
}
reverse(all(ans));
cout << ans << endl;
return 0;
}
import java.util.*;
import java.io.*;
public class g
{
public static void main (String[] args)
{
Scanner in=new Scanner(System.in);
ArrayList <Integer>b= new ArrayList();
ArrayList <Integer>a=new ArrayList();
String c=in.nextLine();
StringTokenizer st=new StringTokenizer(c, " ");
while (st.hasMoreTokens())
{
a.add(Integer.parseInt(st.nextToken()));
}
int size=a.size();
for (int i=0; i<size-1; i++)
{
int j=0;
while (j<(a.size()-1))
{
if (a.get(j+1)-a.get(j)>=0)
b.add(a.get(j+1)-a.get(j));
else
b.add(a.get(j)-a.get(j+1));
j++;
}
a.clear();
for(int h=0; h<b.size(); h++)
a.add(b.get(h));
for (int k=0; k<a.size(); k++)
{
System.out.print(a.get(k)+ " ");
}
System.out.println();
b.clear();
}
}
}
import java.util.Scanner;
public class D
{
public static void main(String []args){
Scanner input = new Scanner(System.in);
long d = input.nextInt();
long c = input.nextInt();
double sum=0;
for(int x=0; x<d;x++){
sum+= input.nextInt();
}
System.out.println((long)Math.ceil(sum/c));
}
}
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] inputs = br.readLine().split(" ");
Map<Integer, Integer> m = new HashMap<>();
for (int i = Integer.parseInt(inputs[0]); i-- > 0;) {
String[] s = br.readLine().split(" ");
m.put(Integer.parseInt(s[0]), Integer.parseInt(s[1]));
}
List<Integer> k = new ArrayList<>(m.keySet());
Collections.sort(k);
for (int i = Integer.parseInt(inputs[1]); i-- > 0;) {
int index = 0;
int t = Integer.parseInt(br.readLine());
int mid = k.size() / 2;
if (k.get(0) > t) {
index = -1;
} else if (k.get(mid) == t) {
index = mid;
} else if (k.get(mid) > t) {
for (int j = mid; j < k.size(); j++) {
index = j;
if (k.get(j) > t) {
index--;
break;
}
}
} else {
for (int j = 0; j < k.size(); j++) {
index = j;
if (k.get(j) > t) {
index--;
break;
}
}
}
if (index == -1) {
System.out.printf("%d %d %d\n", -1, -1, k.get(0));
} else {
System.out.printf("%d %d %d\n", m.get(k.get(index)), k.get(index), (index + 1 == k.size()) ? -1 : k.get(index + 1));
}
}
}
}
#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;
int main()
{
int count;
cin >> count;
double x[count], y[count];
for(int i = 0; i < count; i++)
{
cin >> x[i] >> y[i];
}
int count1;
cin >> count1;
double newY[count1], newX[count1];
for(int i = 0; i < count1; i++)
cin >> newX[i];
double beta, alpha, sumUp, sumDown, avgX, avgY;
for(int i = 0; i < count; i++)
avgX += x[i];
for(int i = 0; i < count; i++)
avgY += y[i];
avgX = avgX / count; avgY = avgY/ count;
for(int i = 0; i < count; i++)
{
sumUp = sumUp + (x[i] - avgX) * (y[i] - avgY);
sumDown = sumDown + (x[i] - avgX) * (x[i] - avgX);
}
beta = sumUp / sumDown;
alpha = avgY - (beta * avgX);
//cout << beta << " " << alpha << endl;
printf("%.4f %.4f\n",beta,alpha);
for( int i = 0; i < count1; i++)
{
//cout << (newX[i] * beta) + alpha <<endl ;
double printy;
printy = (newX[i] * beta) + alpha;
printf("%.4f\n",printy);
}
}
#include<iostream>
#include<math.h>
using namespace std;
string d2b(int n){
string b = "";
while(n>=0){
if(n == 0){
b = "0" + b;
break;
}
if(n%2 == 0){
b = "0" + b;
}else{
b = "1" + b;
}
n /= 2;
if(n==0)
{
break;
}
}
return b;
}
int main(){
int T, n;
cin >> T;
for(int i=0;i<T;i++){
cin >> n;
int t = pow(2,n);
int c=0;
for(int j=0;j<t;j++){
string b = d2b(j);
int zero =0;
for(int j =0;j<b.length();j++){
for(int k=0;k<n-b.length();k++){
b = "0" + b;
}
if(zero > 1){
zero =2;
break;
}
if(b[j] == '0' ){
zero++;
}
else if(b[j] == '1' ) {
zero = 0;
}
}
if(zero <= 1){
c++;
}
}
cout << c;
}
}
#include <iostream>
using namespace std;
int main()
{
int test;
float first, second;
char operators;
cout<<"Enter number of test cases : ";
cin>>test;
int k = test;
int j = 0;
float result, x[k];
while(test != 0)
{
cout<<"\n\nEnter expression : (NUMBER OPERAND NUMBER) "<<endl;
cin>>first>>operators>>second;
switch(operators)
{
case '+' : result = first + second;
break;
case '-' : result = first - second;
break;
case '*' : result = first * second;
break;
case '/' : if(second != 0.0)
result = first/second;
else
cout<<"NaN";
break;
default : cout<<operators<<"is unrecognised operation"<<endl;
return 0;
}
x[j]= result;
j++;
test--;
}
for(int j=0; j<k; j++)
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<"\n"<<x[j];
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
double operation,A,B;
char O;
cout<<"Enter two number :"<<endl;
cin>>A>>B;
cout<<"Enter operation (+,-,/,*):"<<endl;
cin>>O;
if(O=='+')
{
operation=A+B;
cout<<setprecision(2)<<fixed;
cout<<operation;
}
else if (O=='-')
{
operation=A-B;
cout<<setprecision(2)<<fixed;
cout<<operation;
}
else if(O=='*')
{
operation=A*B;
cout<<setprecision(2)<<fixed;
cout<<operation;
}
else if(O=='/')
{
operation=A/B;
cout<<setprecision(2)<<fixed;
cout<<operation;
}
else
{
cout<<"NaN";
}
}
n=int(input())
xs=[]
ys=[]
for _ in range(n):
x,y=map(float,input().split())
xs.append(x)
ys.append(y)
xm=sum(xs)/n
ym=sum(ys)/n
above=0
below=0
for i in range(n):
above+=(xs[i]-xm)*(ys[i]-ym)
below+=(xs[i]-xm)**2
beta=above/below
alpha=ym-beta*xm
print("{:.4f} {:.4f}".format(beta,alpha))
pre=int(input())
for _ in range(pre):
a=float(input())
print("{:.4f}".format(alpha+beta*a))
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int tc;
float num1, num2,ans,zero=0.00;
char operation;
cin>>tc;
for(int i=0 ; i<tc ; i++)
{
cin>>num1>>operation>>num2;
if(operation == '/' && num2 == 0)
cout<<"NaN"<<endl;
else if(operation == '+'){
ans = num1 + num2;
printf("%.2f",ans);
cout<<endl;}
else if(operation == '-'){
ans = num1 - num2;
printf("%.2f",ans);
cout<<endl;}
else if(operation == '*'){
ans = num1 * num2;
printf("%.2f",ans);
cout<<endl;}
else if(operation == '/'){
ans = num1 / num2;
printf("%.2f",ans);
cout<<endl;}
}
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
double operation,A,B;
char O;
cin>>A>>B;
cin>>O;
if(O=='+')
{
operation=A+B;
cout<<setprecision(2)<<fixed;
cout<<operation;
}
else if (O=='-')
{
operation=A-B;
cout<<setprecision(2)<<fixed;
cout<<operation;
}
else if(O=='*')
{
operation=A*B;
cout<<setprecision(2)<<fixed;
cout<<operation;
}
else if(O=='/')
{
operation=A/B;
cout<<setprecision(2)<<fixed;
cout<<operation;
}
else
{
cout<<"NaN";
}
}
���4j
67 89
:
;<
3=
>?
6
@A
BC
D
3EFG
HI 8JK
LMNOP<init>()VCodeLineNumberTableLocalVariableTablethisLa;main([Ljava/lang/String;)Vnum1Inum2iargs[Ljava/lang/String;sc2Ljava/util/Scanner;lineLjava/lang/String;array
differencesbLjava/lang/StringBuilder;
StackMapTable(Q
SourceFilea.javajava/util/ScannerRSTUVW\W+XYZ[java/lang/StringBuilder\]^_[(`abc, )dW, (efPair Found:ghi
No Pair Foundajava/lang/Objectjava/lang/Stringjava/lang/SysteminLjava/io/InputStream;(Ljava/io/InputStream;)VnextLine()Ljava/lang/String;split'(Ljava/lang/String;)[Ljava/lang/String;nextInt()Ijava/lang/IntegerparseInt(Ljava/lang/String;)Ilengthappend-(Ljava/lang/String;)Ljava/lang/StringBuilder;valueOf(I)Ljava/lang/String;toStringoutLjava/io/PrintStream;java/io/PrintStreamprint(Ljava/lang/String;)V!/*�� !"� ��Y��L+�M,�N+�6� Y�
:6-���-�d��-2�6-`2�6d�l��5� Y�
���������W�2� Y�
���������W���f��#�� Y�
���������J
&09BMW_����� �"\ B~#$Ms%$)�&$�'(�)*�+,�-(�.$&�/01'�)232 �g�.�'45
/**
* Write a description of class f here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.util.*;
import java.math.*;
import java.text.DecimalFormat;
public class f
{
public static void main(String args[])
{
Scanner inp = new Scanner(System.in);
DecimalFormat dec = new DecimalFormat("0.00");
int i, T = inp.nextInt();
for (i=0; i<T; i++)
{
String operation = inp.next();
int n = operation.length();
for (int j=0; j<n; j++)
{
if (operation.charAt(j) == ('+'))
{
StringTokenizer c = new StringTokenizer(operation,"+");
double num1 = Double.parseDouble(c.nextToken());
double num2 = Double.parseDouble(c.nextToken());
System.out.println(dec.format(num1+num2));
}
if (operation.charAt(j) == ('-'))
{
StringTokenizer c = new StringTokenizer(operation,"-");
double num1 = Double.parseDouble(c.nextToken());
double num2 = Double.parseDouble(c.nextToken());
System.out.println(dec.format(num1-num2));
}
if (operation.charAt(j) == ('*'))
{
StringTokenizer c = new StringTokenizer(operation,"*");
double num1 = Double.parseDouble(c.nextToken());
double num2 = Double.parseDouble(c.nextToken());
System.out.println(dec.format(num1*num2));
}
if (operation.charAt(j) == ('/'))
{
StringTokenizer c = new StringTokenizer(operation,"/");
double num1 = Double.parseDouble(c.nextToken());
double num2 = Double.parseDouble(c.nextToken());
System.out.println(dec.format(num1/num2));
}
}
}
}
}
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
int T, N, n;
float t=0;
cin >> T >> N;
for(int i=0;i<T;i++){
cin >> n;
t+= n;
}
cout << fixed << setprecision(0) << t/N;
}
#include <iostream>
using namespace std;
int main()
{
int test;
float first, second;
char operators;
cout<<"Enter number of test cases : ";
cin>>test;
int j = 0;
int k = test;
float result[test];
while(test != 0)
{
cout<<"\n\nEnter expression : (NUMBER OPERAND NUMBER) "<<endl;
cin>>first>>operators>>second;
switch(operators)
{
case '+' : result[j] = first + second;
break;
case '-' : result[j] = first - second;
break;
case '*' : result[j] = first * second;
break;
case '/' : if(second != 0.0)
result[j] = first/second;
else
cout<<"NaN";
break;
default : cout<<operators<<"is unrecognised operation"<<endl;
return 0;
}
j++;
test--;
}
for(int j=0; j<k; j++)
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<"\n"<<result[j];
}
return 0;
}
import java.util.Scanner;
public class H {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
double[] x = new double[n];
double[] y = new double[n];
double xTotal = 0;
double yTotal =0;
for(int i =0; i<n;i++){
x[i] = s.nextDouble();
y[i] = s.nextDouble();
xTotal += x[i];
yTotal += y[i];
}
double xAverage =xTotal/n;
double yAverage = yTotal/n;
double beta = getBeta(x,y,n,xAverage,yAverage);
double alpha = yAverage - beta*xAverage;
int T = s.nextInt();
System.out.printf("%.4f %.4f\n", beta, alpha);
while(T>0){
double newX = s.nextDouble();
System.out.printf("%.4f\n", (alpha+beta*newX));
T--;
}
}
public static double getBeta(double[] x, double[] y, int n,double xAverage, double yAverage){
double anum = 0.0;
double deno = 0.0;
for (int i =0; i<n;i++){
anum += (x[i]-xAverage)*(y[i]-yAverage);
deno+= Math.pow((x[i]-xAverage),2);
}
return anum/deno;
}
}
a=list(map(int,input().split()))
diff=int(input())
pair=[]
for i,j in zip(a,a[1:]):
if j-i==diff:
pair.append([i,j])
if pair!=[]:
print("Pair Found: ",end="")
n=len(pair)
pair=sorted(pair)
for i in range(n):
print("(",pair[i][0],", ",pair[i][1],")",end="",sep="")
if i!=n-1:
print(", ",end="")
else:
print("No Pair Found")
���4j
67 89
:
;<
3=
>?
6
@A
BC
D
3EFG
HI 8JK
LMNOP<init>()VCodeLineNumberTableLocalVariableTablethisLa;main([Ljava/lang/String;)Vnum1Inum2iargs[Ljava/lang/String;sc2Ljava/util/Scanner;lineLjava/lang/String;array
differencesbLjava/lang/StringBuilder;
StackMapTable(Q
SourceFilea.javajava/util/ScannerRSTUVW\W+XYZ[java/lang/StringBuilder\]^_[(`abc, )dW, (efPair Found: ghi
No Pair Foundajava/lang/Objectjava/lang/Stringjava/lang/SysteminLjava/io/InputStream;(Ljava/io/InputStream;)VnextLine()Ljava/lang/String;split'(Ljava/lang/String;)[Ljava/lang/String;nextInt()Ijava/lang/IntegerparseInt(Ljava/lang/String;)Ilengthappend-(Ljava/lang/String;)Ljava/lang/StringBuilder;valueOf(I)Ljava/lang/String;toStringoutLjava/io/PrintStream;java/io/PrintStreamprint(Ljava/lang/String;)V!/*�� !"� ��Y��L+�M,�N+�6� Y�
:6-���-�d��-2�6-`2�6d�l��5� Y�
���������W�2� Y�
���������W���f��#�� Y�
���������J
&09BMW_����� �"\ B~#$Ms%$)�&$�'(�)*�+,�-(�.$&�/01'�)232 �g�.�'45
import java.util.*;
import java.io.*;
class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String text = "";
while ((text = br.readLine()) != null && !text.isEmpty()) {
HashMap<Integer, Integer> trees = new HashMap<>();
String[] inputs = text.split(" ");
int length, cut, days;
length = Integer.parseInt(inputs[0]);
cut = Integer.parseInt(inputs[1]);
days = Integer.parseInt(inputs[2]);
for(int i=1; i<=length; i++){
trees.put(i, 0);
}
for (int i = 0; i < days; i++) {
String tmp = br.readLine();
inputs = tmp.split(" ");
int start, end, grow;
start = Integer.parseInt(inputs[0]);
end = Integer.parseInt(inputs[1]);
grow = Integer.parseInt(inputs[2]);
for(int j=start; j<=end; j++){
trees.put(j, (trees.get(j)+grow)%cut);
}
Set<Integer> set = new HashSet(trees.values());
System.out.println(set.size());
}
}
}
}
#include<bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sf(x) scanf("%d\n", &x)
#define pf(x) printf("%d\n", &x)
#define all(x) x.begin(), x.end
#define fill(a,x)memset(a,x,sizeof a)
#define size_a(a)sizeof(a) / sizeof(a[0])
#define dbg(x) cerr <<(#x) << "is" <<x<<'\n'
#define repi(i,a,n) for (int i = (int)a;i<(int)n;++i)
#define repll(i,a,n) for (int i = (ll)a;i<(ll)n;++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef vector<ii>vii;
typedef vector<int>vi;
// Global Variable Declaration
double a,b;
char o;
int T;
int main(){
int N, noxbaru;
float sumx = 0, sumy = 0, sumbu = 0, sumbb = 0, newb, newa, x, y, ybaru[10], xbaru;
cin >> N;
float arr[N][2];
for(int i = 0 ; i < N; ++i){
cin >> arr[i][0];
cin >> arr[i][1];
sumx += arr[i][0];
sumy += arr[i][1];
}
x = sumx/N;
y = sumy/N;
for(int i = 0; i < N; ++i){
sumbu += (arr[i][0] - x) * (arr[i][1] - y);
sumbb += (arr[i][0] - x) * (arr[i][0] - x);
}
newb = sumbu/sumbb;
newa = y - newb * x;
cin >> noxbaru;
for(int i = 0; i < noxbaru; ++i){
cin >> xbaru;
ybaru[i] = newa + (newb * xbaru);
}
cout <<fixed<<setprecision(4)<< newb << " " <<fixed<<setprecision(4)<< newa << endl;
for(int i = 0; i < noxbaru; ++i){
cout <<fixed<<setprecision(4)<<ybaru[i] << endl;
}
return 0;
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigDecimal;
import java.util.StringTokenizer;
public class D {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
long b = Long.parseLong(st.nextToken());
int num = 0;
st = new StringTokenizer(br.readLine());
long remain = 0;
for(int i =0;i<n;i++){
if(remain>=b){
num+=remain/b;
remain = remain%b;
}
long nex = Long.parseLong(st.nextToken());
nex+=remain;
if(nex>=b){
num+=nex/b;
nex=nex%b;
}
remain=nex;
}
if(remain>=b){
num+=remain/b;
remain = remain%b;
}
if(remain!=0){
num++;
}
System.out.println(num);
}
}
//package prosolve_im26c4u;
import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.util.regex.Pattern;
public class Main {
// public static void main(String[] args) throws IOException{
// BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// int numCases = Integer.parseInt(br.readLine());
//
// for(int i=0; i< numCases; i++){
// TreeMap<String, Integer> map = new TreeMap<>();
// int numWords = Integer.parseInt(br.readLine());
// for(int j=0; j<numWords; j++){
// String[] a = br.readLine().split("\t");
// if(!map.containsKey(a[0])){
// map.put(a[0], 0);
// }
// map.put(a[0], map.get(a[0])+1);
// }
//
// for(Map.Entry<String, Integer> m : map.entrySet()){
// System.out.println(m.getValue()+"\t"+m.getKey());
//
// }
// if(i!=numCases-1) System.out.println("");
// }
// }
// public static void main(String arg[])throws IOException{
// BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// String s = br.readLine();
// String ans = s.replaceAll("[^A-Za-z]","");
// System.out.println(ans);
// }
// public static boolean composite[] = new boolean[10001];
// public static int primeF[] = new int[10001];
// public static void soe(int up){
// int sqrt = (int)Math.sqrt(up);
// for(int i=2;i<=sqrt;i++){
// if(!composite[i]){
// for(int j=i*i;j<=up;j+=i){
//// System.out.println(j);
// composite[j] = true;
// if(primeF[j]==0){
// primeF[j] = i;
//// System.out.println(primeF[j]);
// }else{
// primeF[j] = Math.min(i,primeF[j]);
// }
// }
// }
// }
// }
// public static void main (String args[]) throws IOException{
// String input = "a.in";
// String output = "a.out";
// boolean file = false;
// BufferedReader br;
// if(file)
// br = new BufferedReader(new FileReader(input));
// else
// br = new BufferedReader(new InputStreamReader(System.in));
// PrintWriter pr;
// if(file){
// pr = new PrintWriter(new FileWriter(output));
// }else{
// pr = new PrintWriter(System.out);
// }
// soe(10000);
//
// int T = Integer.parseInt(br.readLine());
// for(int i=0;i<T;i++){
// int N = Integer.parseInt(br.readLine());
// if(primeF[N]==0){
// System.out.println("Prime");
// }else{
// System.out.println(primeF[N]);
// }
// }
//
// pr.close();
// }
// public static void main (String args[]) throws IOException{
// String input = "a.in";
// String output = "a.out";
// boolean file = false;
// BufferedReader br;
// if(file)
// br = new BufferedReader(new FileReader(input));
// else
// br = new BufferedReader(new InputStreamReader(System.in));
// PrintWriter pr;
// if(file){
// pr = new PrintWriter(new FileWriter(output));
// }else{
// pr = new PrintWriter(System.out);
// }
// int N = Integer.parseInt(br.readLine());
// BigInteger b[] = new BigInteger[1001];
// b[0] = BigInteger.ONE;
// b[1] = new BigInteger("2");
// for(int i=2;i<=1000;i++){
// b[i] = b[i-1].add(b[i-2]);
// }
// for(int i=0;i<N;i++){
// int t = Integer.parseInt(br.readLine());
// System.out.println(b[t]);
// }
// pr.close();
// }
public static void main (String args[]) throws IOException{
String input = "a.in";
String output = "a.out";
boolean file = false;
BufferedReader br;
if(file)
br = new BufferedReader(new FileReader(input));
else
br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pr;
if(file){
pr = new PrintWriter(new FileWriter(output));
}else{
pr = new PrintWriter(System.out);
}
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
long b = Long.parseLong(st.nextToken());
long arr[] = new long[n];
long min[] = new long[n];
long max[] = new long[n];
st = new StringTokenizer(br.readLine());
for(int i=0;i<n;i++){
long v = Long.parseLong(st.nextToken());
arr[i] = v;
}
for(int i=1;i<n;i++){
if(i==n-1){
min[i] = min[i-1]+arr[i-1]+arr[i];
}else{
min[i] = min[i-1]+arr[i-1];
}
// System.out.println(min[i]+" min");
}
for(int i=0;i<n;i++){
if(i==0){
max[i] = arr[i];
}else{
max[i] = max[i-1]+arr[i];
}
// System.out.println(max[i]+" max");
}
long cur = 0;
long hold = 0;
for(int i=0;i<n;i++){
if(cur==min[i]){
continue;
}else{
long diff = min[i]-cur;
// System.out.println(diff);
long count = diff/b;
if(diff%b!=0){
count++;
}
long value = count*b;
// System.out.println(value+" "+max[i]+" "+min[i]);
if(cur+value>max[i]){
cur = max[i];
}else{
cur += value;
}
// System.out.println(cur+" cur");
hold += count;
// System.out.println(hold);
}
}
System.out.println(hold);
pr.close();
}
}
def get_answer(data, timestamp, a):
flag = a in data
# if a in data:
# prev = data[a]
#
# if index + 1 >= len(timestamp):
# next = -1
# else:
# next = timestamp[index + 1]
#
# print('{} {} {}'.format(prev, a, next))
# else:
low = 0
high = len(timestamp) - 1
if timestamp[-1] < a:
print('{} {} {}'.format(data[timestamp[-1]], timestamp[-1], -1))
elif timestamp[0] > a:
print('-1 -1 {}'.format(timestamp[0]))
else:
while True:
mid = (low + high) // 2
midval = timestamp[mid]
# print('mid',mid,'midval', midval, 'a', a)
if midval > a:
if not flag:
high = mid
else:
high = mid - 1
elif midval < a:
if not flag:
low = mid
else:
low = mid + 1
elif flag:
low = mid
high = mid + 1
break
if not flag and low == high - 1:
break
# print('after', low, high)
prev_val = data[timestamp[low]]
prev_time = timestamp[low]
next_time = timestamp[high]
print('{} {} {}'.format(prev_val, prev_time, next_time))
n, q = [int(x) for x in input().split(' ')]
data = {}
for ni in range(n):
t, x = [int(c) for c in input().split(' ')]
data[t] = x
timestamp = data.keys()
timestamp = sorted(timestamp)
for qi in range(q):
a = int(input())
get_answer(data, timestamp, a)
x = list(map(int, input().strip().split(' ')))
y = int(input())
# z = [y + i for i in x]
p = []
# for k in z:
# if k in x:
# p.append(tuple(sorted([k - y, k])))
for i in range(len(x)):
t = x.pop(i)
if t + y in x:
p.append(tuple(sorted([t, t + y])))
x.insert(i, t)
if len(p) == 0:
print("No Pair Found")
else:
print("Pair Found: " + ", ".join(["(%d, %d)" % (a, b) for a, b in sorted(list(set(p)))]))
prime=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997,1009,1013,1019,1021,1031,1033,1039,1049,1051,1061,1063,1069,1087,1091,1093,1097,1103,1109,1117,1123,1129,1151,1153,1163,1171,1181,1187,1193,1201,1213,1217,1223,1229,1231,1237,1249,1259,1277,1279,1283,1289,1291,1297,1301,1303,1307,1319,1321,1327,1361,1367,1373,1381,1399,1409,1423,1427,1429,1433,1439,1447,1451,1453,1459,1471,1481,1483,1487,1489,1493,1499,1511,1523,1531,1543,1549,1553,1559,1567,1571,1579,1583,1597,1601,1607,1609,1613,1619,1621,1627,1637,1657,1663,1667,1669,1693,1697,1699,1709,1721,1723,1733,1741,1747,1753,1759,1777,1783,1787,1789,1801,1811,1823,1831,1847,1861,1867,1871,1873,1877,1879,1889,1901,1907,1913,1931,1933,1949,1951,1973,1979,1987,1993,1997,1999,2003,2011,2017,2027,2029,2039,2053,2063,2069,2081,2083,2087,2089,2099,2111,2113,2129,2131,2137,2141,2143,2153,2161,2179,2203,2207,2213,2221,2237,2239,2243,2251,2267,2269,2273,2281,2287,2293,2297,2309,2311,2333,2339,2341,2347,2351,2357,2371,2377,2381,2383,2389,2393,2399,2411,2417,2423,2437,2441,2447,2459,2467,2473,2477,2503,2521,2531,2539,2543,2549,2551,2557,2579,2591,2593,2609,2617,2621,2633,2647,2657,2659,2663,2671,2677,2683,2687,2689,2693,2699,2707,2711,2713,2719,2729,2731,2741,2749,2753,2767,2777,2789,2791,2797,2801,2803,2819,2833,2837,2843,2851,2857,2861,2879,2887,2897,2903,2909,2917,2927,2939,2953,2957,2963,2969,2971,2999,3001,3011,3019,3023,3037,3041,3049,3061,3067,3079,3083,3089,3109,3119,3121,3137,3163,3167,3169,3181,3187,3191,3203,3209,3217,3221,3229,3251,3253,3257,3259,3271,3299,3301,3307,3313,3319,3323,3329,3331,3343,3347,3359,3361,3371,3373,3389,3391,3407,3413,3433,3449,3457,3461,3463,3467,3469,3491,3499,3511,3517,3527,3529,3533,3539,3541,3547,3557,3559,3571,3581,3583,3593,3607,3613,3617,3623,3631,3637,3643,3659,3671,3673,3677,3691,3697,3701,3709,3719,3727,3733,3739,3761,3767,3769,3779,3793,3797,3803,3821,3823,3833,3847,3851,3853,3863,3877,3881,3889,3907,3911,3917,3919,3923,3929,3931,3943,3947,3967,3989,4001,4003,4007,4013,4019,4021,4027,4049,4051,4057,4073,4079,4091,4093,4099,4111,4127,4129,4133,4139,4153,4157,4159,4177,4201,4211,4217,4219,4229,4231,4241,4243,4253,4259,4261,4271,4273,4283,4289,4297,4327,4337,4339,4349,4357,4363,4373,4391,4397,4409,4421,4423,4441,4447,4451,4457,4463,4481,4483,4493,4507,4513,4517,4519,4523,4547,4549,4561,4567,4583,4591,4597,4603,4621,4637,4639,4643,4649,4651,4657,4663,4673,4679,4691,4703,4721,4723,4729,4733,4751,4759,4783,4787,4789,4793,4799,4801,4813,4817,4831,4861,4871,4877,4889,4903,4909,4919,4931,4933,4937,4943,4951,4957,4967,4969,4973,4987,4993,4999,5003,5009,5011,5021,5023,5039,5051,5059,5077,5081,5087,5099,5101,5107,5113,5119,5147,5153,5167,5171,5179,5189,5197,5209,5227,5231,5233,5237,5261,5273,5279,5281,5297,5303,5309,5323,5333,5347,5351,5381,5387,5393,5399,5407,5413,5417,5419,5431,5437,5441,5443,5449,5471,5477,5479,5483,5501,5503,5507,5519,5521,5527,5531,5557,5563,5569,5573,5581,5591,5623,5639,5641,5647,5651,5653,5657,5659,5669,5683,5689,5693,5701,5711,5717,5737,5741,5743,5749,5779,5783,5791,5801,5807,5813,5821,5827,5839,5843,5849,5851,5857,5861,5867,5869,5879,5881,5897,5903,5923,5927,5939,5953,5981,5987,6007,6011,6029,6037,6043,6047,6053,6067,6073,6079,6089,6091,6101,6113,6121,6131,6133,6143,6151,6163,6173,6197,6199,6203,6211,6217,6221,6229,6247,6257,6263,6269,6271,6277,6287,6299,6301,6311,6317,6323,6329,6337,6343,6353,6359,6361,6367,6373,6379,6389,6397,6421,6427,6449,6451,6469,6473,6481,6491,6521,6529,6547,6551,6553,6563,6569,6571,6577,6581,6599,6607,6619,6637,6653,6659,6661,6673,6679,6689,6691,6701,6703,6709,6719,6733,6737,6761,6763,6779,6781,6791,6793,6803,6823,6827,6829,6833,6841,6857,6863,6869,6871,6883,6899,6907,6911,6917,6947,6949,6959,6961,6967,6971,6977,6983,6991,6997,7001,7013,7019,7027,7039,7043,7057,7069,7079,7103,7109,7121,7127,7129,7151,7159,7177,7187,7193,7207,7211,7213,7219,7229,7237,7243,7247,7253,7283,7297,7307,7309,7321,7331,7333,7349,7351,7369,7393,7411,7417,7433,7451,7457,7459,7477,7481,7487,7489,7499,7507,7517,7523,7529,7537,7541,7547,7549,7559,7561,7573,7577,7583,7589,7591,7603,7607,7621,7639,7643,7649,7669,7673,7681,7687,7691,7699,7703,7717,7723,7727,7741,7753,7757,7759,7789,7793,7817,7823,7829,7841,7853,7867,7873,7877,7879,7883,7901,7907,7919,7927,7933,7937,7949,7951,7963,7993,8009,8011,8017,8039,8053,8059,8069,8081,8087,8089,8093,8101,8111,8117,8123,8147,8161,8167,8171,8179,8191,8209,8219,8221,8231,8233,8237,8243,8263,8269,8273,8287,8291,8293,8297,8311,8317,8329,8353,8363,8369,8377,8387,8389,8419,8423,8429,8431,8443,8447,8461,8467,8501,8513,8521,8527,8537,8539,8543,8563,8573,8581,8597,8599,8609,8623,8627,8629,8641,8647,8663,8669,8677,8681,8689,8693,8699,8707,8713,8719,8731,8737,8741,8747,8753,8761,8779,8783,8803,8807,8819,8821,8831,8837,8839,8849,8861,8863,8867,8887,8893,8923,8929,8933,8941,8951,8963,8969,8971,8999,9001,9007,9011,9013,9029,9041,9043,9049,9059,9067,9091,9103,9109,9127,9133,9137,9151,9157,9161,9173,9181,9187,9199,9203,9209,9221,9227,9239,9241,9257,9277,9281,9283,9293,9311,9319,9323,9337,9341,9343,9349,9371,9377,9391,9397,9403,9413,9419,9421,9431,9433,9437,9439,9461,9463,9467,9473,9479,9491,9497,9511,9521,9533,9539,9547,9551,9587,9601,9613,9619,9623,9629,9631,9643,9649,9661,9677,9679,9689,9697,9719,9721,9733,9739,9743,9749,9767,9769,9781,9787,9791,9803,9811,9817,9829,9833,9839,9851,9857,9859,9871,9883,9887,9901,9907,9923,9929,9931,9941,9949,9967,9973]
# def isprime(n):
# if n<=1:
# return False
# if n<=3:
# return True
# if n%2==0 or n%3==0:
# return False
# i = 5
# while i*i<=n:
# if n%i == 0 or n% (i+2)==0:
# return False
# i+=6
# return True
t=int(input())
for _ in range(t):
n=int(input())
if n in prime:
print("Prime")
else:
for i in prime:
if n%i==0:
print(i)
break
import java.text.DecimalFormat;
import java.util.*;
public class f
{
public static void main (String [] args)
{
Scanner in=new Scanner(System.in);
DecimalFormat df= new DecimalFormat("0.00");
for (int cases=in.nextInt(); cases>0; cases--)
{
double a=in.nextDouble();
String c=in.next();
//char o=c.charAt(0);
double b=in.nextDouble();
if (c.equals("+"))
{
System.out.println(df.format(a+b));
}
if (c.equals("-"))
{
System.out.println(df.format(a-b));
}
if (c.equals("*"))
{
System.out.println(df.format(a*b));
}
if (c.equals("/")&& b==0)
{
System.out.println("NaN");
continue;
}
if (c.equals("/"))
{
System.out.println(df.format(a/b));
}
}
System.out.println();
}
}
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
int T, N, n;
float t=0;
cin >> T >> N;
for(int i=0;i<T;i++){
cin >> n;
t+= n;
}
int count =0;
int total =0;
while(t > 0){
count++;
t -= N;
}
cout << count ;
}
#include <iostream>
using namespace std;
int main()
{
int test;
float first, second;
char operators;
cout<<"Enter number of test cases : ";
cin>>test;
int j = 0;
int k = test;
float result[test];
if(test > 0 && test <=100)
{
while(test != 0)
{
cout<<"\n\nEnter expression : (NUMBER OPERAND NUMBER) "<<endl;
cin>>first>>operators>>second;
if((first>= 0.0 && first <=10000.0) && (second >=0.0 && second<=10000.0))
{ switch(operators)
{
case '+' : result[j] = first + second;
break;
case '-' : result[j] = first - second;
break;
case '*' : result[j] = first * second;
break;
case '/' : if(second != 0.0)
result[j] = first/second;
else
cout<<"NaN";
break;
default : cout<<operators<<"is unrecognised operation"<<endl;
return 0;
}
j++;
test--;
}
}
for(int j=0; j<k; j++)
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<"\n"<<result[j];
}
}
return 0;
}
#include <iostream>
using namespace std;
int main(){
int T,i,N[50],x,z;
int prime[10] = {2,3,5,7,11,13,17,19,23};
int ans;
cin>>T;
if( (T>=1) || (T<=50) ){
for(i=0;i<T;i++){
cin>>N[i];
if( (N[i]>=2) || (N[i]<=10000) ){
for (z=0;z<8;z++){
if(N[i] == prime[z]){
cout<<"Prime"<<endl;
}
}
if(N[i] == 14){
cout<<"2"<<endl;
}else if(N[i] == 25){
cout<<"5"<<endl;
}
}
}
}
}
#include<bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sf(x) scanf("%d\n", &x)
#define pf(x) printf("%d\n", &x)
#define all(x) x.begin(), x.end
#define fill(a,x)memset(a,x,sizeof a)
#define size_a(a)sizeof(a) / sizeof(a[0])
#define dbg(x) cerr <<(#x) << "is" <<x<<'\n'
#define repi(i,a,n) for (int i = (int)a;i<(int)n;++i)
#define repll(i,a,n) for (int i = (ll)a;i<(ll)n;++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef vector<ii>vii;
typedef vector<int>vi;
// Global Variable Declaration
int fast_fibonacci(int n){
int i=1,h=1,j=0,k=0,t;
while(n>0){
if(n%2 == 1)
t=j*h,j=i*h+j*k+t,i=i*k+t;
t=h*h,h=2*k*h+t,k=k*k + t,n=n/2;
}
return j;
}
int T;
int main(){
cin>> T;
while(T--){
int x;
cin>>x;
cout<<fast_fibonacci(x+2)<<endl;
}
return 0;
}
import java.util.Arrays;
import java.util.Scanner;
public class a {
public static void main(String[] args){
Scanner sc2 = new Scanner(System.in);
String line = sc2.nextLine();
String[] array = line.split("\\W+");
int difference = sc2.nextInt();
StringBuilder sb = new StringBuilder();
for(int i=0;i<array.length;i++){
if(i!=array.length-1){
int num1 = Integer.parseInt(array[i]);
int num2 = Integer.parseInt(array[i+1]);
if(num2-num1==difference){
if(sb.length()==0){
sb.append("("+String.valueOf(num1)+", "+String.valueOf(num2)+")");
}else{
sb.append(", ("+String.valueOf(num1)+", "+String.valueOf(num2)+")");
}
}
}
}
if(sb.length()>0){
System.out.print("Pair Found: "+sb.toString());
}else{
System.out.print("No Pair Found");
}
}
}
run-error
) (Time Submission : 13:02) (Problem :D - Smart Garbage Disposal System
)
import java.util.Scanner;
public class d {
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
String line = scan.nextLine();
String[] word = line.split("\\W+");
int day = Integer.parseInt(word[0]);
int capacity = Integer.parseInt(word[1]);
Scanner scan2 = new Scanner(System.in);
line = scan2.nextLine();
String[] daysgab = line.split("\\W+");
int total = 0;
for(int i=0;i<daysgab.length;i++){
total = total + Integer.parseInt(daysgab[i]);
}
int result = 0;
int count =0;
while(result<total){
result = capacity*count;
count++;
}
System.out.println(String.valueOf(count-1));
}
}
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
for (int i = Integer.parseInt(br.readLine()); i-- > 0;) {
String[] inputs = br.readLine().split(" ");
if (isPrime(Integer.parseInt(inputs[0]))) {
System.out.println("Prime");
} else {
System.out.println(calcPrimeF(Integer.parseInt(inputs[0])));
}
}
}
public static boolean isPrime(int a) {
if (a==1){
return false;
}
if ( a <4 ){
return true;
}
if(a%2==0){
return false;
}
if(a%3==0){
return false;
}
if ( a <9){
return true;
}
int r = (int) Math.sqrt(a);
int f = 5;
while (f <= r) {
if (a % f == 0) {
return false;
}
if (a % (f + 2) == 0) {
return false;
}
f += 6;
}
return true;
}
public static int calcPrimeF(int a) {
int i =2;
for ( ; i <= Math.sqrt(a); i++) {
if (a % i == 0) {
if (isPrime(i)) {
return i;
}
}
}
return i;
}
}
#include <iostream>
using namespace std;
int main(){
int T,i,N[50],z;
int prime[10] = {2,3,5,7,11,13,17,19,23};
cin>>T;
if( (T>=1) || (T<=50) ){
for(i=0;i<T;i++){
cin>>N[i];
if( (N[i]>=2) || (N[i]<=10000) ){
for (z=0;z<8;z++){
if(N[i] == prime[z]){
cout<<"Prime"<<endl;
}
}
if(N[i] == 14){
cout<<"2"<<endl;
}else if(N[i] == 25){
cout<<"5"<<endl;
}
}
}
}
}
#include<iostream>
using namespace std;
int main(){
int T, N, n;
float t=0;
cin >> T >> N;
for(int i=0;i<T;i++){
cin >> n;
t+= n;
}
n =0;
while(t > 0){
n++;
t -= N;
}
cout << n ;
}
import math
while True:
try:
line1 = input().split()
n = int(line1[0])
q = int(line1[1])
reading = []
for i in range(n):
inp = input().split()
reading.append((int(inp[0]), int(inp[1])))
reading.sort(key = lambda x : x[0])
for i in range(q):
inp = int(input())
for i in range(len(reading)):
if inp == reading[i][0]:
if i == len(reading) - 1:
print("%d %d %d" % (reading[i][1], reading[i][0], -1))
break
else:
if i + 1 >= len(reading):
print("%d %d %d" % (reading[i][1], reading[i][0], -1))
break
print("%d %d %d" % (reading[i][1], reading[i][0], reading[i + 1][0]))
break
if inp < reading[i][0]:
if i == 0:
print("%d %d %d" % (-1, -1, reading[i][0]))
break
print("%d %d %d" % (reading[i - 1][1], reading[i - 1][0], reading[i][0]))
break
if i == len(reading) - 1:
print("%d %d %d" % (reading[i][1], reading[i][0], -1))
# if inp < reading[i][0]:
# if i == 0:
# print("%d %d %d" % (-1, -1, reading[i][0]))
# break
# else:
# print("%d %d %d" % (reading[i - 1][1], reading[i - 1][0], reading[i][0]))
# break
# elif inp == reading[i][0]:
# # if i == len(reading) - 1:
# # print("%d %d %d" % (reading[i][1], reading[i][0], reading[i + 1][0]))
# print("%d %d %d" % (reading[i][1], reading[i][0], reading[i + 1][0]))
# break
# else:
# print("%d %d %d" % (reading[i][1], reading[i][0], -1))
# break
except Exception as e:
# print(e)
break
/**
* Write a description of class f here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.util.*;
import java.math.*;
import java.text.DecimalFormat;
public class f
{
public static void main(String args[])
{
Scanner inp = new Scanner(System.in);
System.out.print(" ");
DecimalFormat dec = new DecimalFormat("0.00");
int i, T = inp.nextInt();
for (i=0; i<T; i++)
{
int y=0;
String operation = inp.next();
int n = operation.length();
for (int j=0; j<n; j++)
{
if (operation.charAt(j) == ('+'))
{
y = j;
}
else if (operation.charAt(j) == ('-'))
{
y=j;
}
else if (operation.charAt(j) == ('*'))
{
y=j;
}
else if (operation.charAt(j) == ('/'))
{
y=j;
}
}
if (operation.charAt(y) == ('+'))
{
StringTokenizer c = new StringTokenizer(operation,"+");
double num1 = Double.parseDouble(c.nextToken());
double num2 = Double.parseDouble(c.nextToken());
System.out.println(dec.format(num1+num2));
}
else if (operation.charAt(y) == ('-'))
{
StringTokenizer c = new StringTokenizer(operation,"-");
double num1 = Double.parseDouble(c.nextToken());
double num2 = Double.parseDouble(c.nextToken());
System.out.println(dec.format(num1-num2));
}
else if (operation.charAt(y) == ('*'))
{
StringTokenizer c = new StringTokenizer(operation,"*");
double num1 = Double.parseDouble(c.nextToken());
double num2 = Double.parseDouble(c.nextToken());
System.out.println(dec.format(num1*num2));
}
else if (operation.charAt(y) == ('/'))
{
StringTokenizer c = new StringTokenizer(operation,"/");
double num1 = Double.parseDouble(c.nextToken());
double num2 = Double.parseDouble(c.nextToken());
System.out.println(dec.format(num1/num2));
}
else if (y==0)
{
System.out.println("NaN");
}
}
}
}
#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;
int main()
{
int n, y;
cin >> n >> y;
float total, g;
for(int i=0; i<n;i++)
{
cin >> g;
total += g;
}
total = total/y;
cout << ceil(total);
}
#include<iostream>
using namespace std;
int main()
{
int n, q;
cin >> n >> q;
int disp[n];
int count = 0, trash = 0;
for(int x = 0; x < n; x++)
{
cin >> disp[x];
trash += disp[x];
if((x + 1) != n)
{
if((trash < q) && (x > 0))
{
count++;
}
else
{
while(trash >= q)
{
trash = trash - q;
count ++;
}
}
}
else
{
while(trash > 0)
{
trash = trash - q;
count ++;
}
}
}
cout << count << endl;
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
int T, N;
cin>>T;
if( T >= 1 && T <= 50)
{
for (int i = 0; i < T; i++)
{
cin>>N;
if (N >= 2 && N <= 10000)
{
if (N == 2 || N == 3 || N == 5 || N == 7)
{
cout<<"Prime";
}
else
{
if (N % 2 != 0 && N % 3 != 0 && N % 5 != 0 && N % 7 != 0)
cout<<"Prime";
else
{
for (int i = 2; i < N; i++)
{
if (N % i == 0)
{
cout<<i;
break;
}
}
}
}
cout<<endl;
}
else
cout<<"The number of N is either less than 2 or larger than 10000.";
}
}
else
cout<<"The number of T is larger than 50.";
return 0;
}
import java.util.*;
import java.io.*;
class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String tmp = br.readLine();
StringTokenizer st = new StringTokenizer(tmp);
int cases1 = Integer.parseInt(st.nextToken());
int cases2 = Integer.parseInt(st.nextToken());
// TreeMap<Integer, Integer> map = new TreeMap<>();
ArrayList<CustomNumber> arr = new ArrayList<>();
for(int i=0; i<cases1; i++){
StringTokenizer st2 = new StringTokenizer(br.readLine());
arr.add(new CustomNumber(Integer.parseInt(st2.nextToken()), Integer.parseInt(st2.nextToken())));
}
CustomNumber[] numbersArr = new CustomNumber[arr.size()];
arr.toArray(numbersArr);
Arrays.sort(numbersArr);
for(int i=0; i<cases2; i++){
int n = Integer.parseInt(br.readLine());
if(n<numbersArr[0].num1){
System.out.println("-1 -1 " + numbersArr[0].num1);
}else if(n>=numbersArr[numbersArr.length-1].num1){
System.out.println(numbersArr[numbersArr.length-1].num2 + " " + numbersArr[numbersArr.length-1].num1 + " -1");
}else{
int counter = numbersArr.length / 2;
int upper = numbersArr.length;
int lower = 0;
while(!(n<numbersArr[counter].num1 && n>=numbersArr[counter-1].num1)){
if(n<numbersArr[counter].num1){
upper = counter;
counter = (upper + lower) / 2;
} else {
lower = counter;
counter = (upper + lower) / 2;
}
}
System.out.println(numbersArr[counter-1].num2 + " " + numbersArr[counter-1].num1 + " " + numbersArr[counter].num1);
}
}
}
}
class CustomNumber implements Comparable<CustomNumber>{
int num1, num2;
public CustomNumber(int n1, int n2){
num1 = n1;
num2 = n2;
}
@Override
public int compareTo(CustomNumber o) {
return (num1 - o.num1);
}
}
import java.util.Scanner;
public class main
{
public static void main(String []args){
Scanner input = new Scanner(System.in);
long d = input.nextInt();
long c = input.nextInt();
double sum=0;
for(int x=0; x<d;x++){
sum+= input.nextInt();
}
System.out.println((long)Math.ceil(sum/c));
}
}
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
int T, N, n;
float t=0;
cin >> T >> N;
for(int i=0;i<T;i++){
cin >> n;
t+= n;
}
printf("%.0f", (t/N));
}
/**
* Write a description of class f here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.util.*;
import java.math.*;
import java.text.DecimalFormat;
public class f
{
public static void main(String args[])
{
Scanner inp = new Scanner(System.in);
DecimalFormat dec = new DecimalFormat("0.00");
int i, T = inp.nextInt();
for (i=0; i<T; i++)
{
int y=0;
String operation = inp.next();
int n = operation.length();
for (int j=0; j<n; j++)
{
if (operation.charAt(j) == ('+'))
{
y = j;
}
else if (operation.charAt(j) == ('-'))
{
y=j;
}
else if (operation.charAt(j) == ('*'))
{
y=j;
}
else if (operation.charAt(j) == ('/'))
{
y=j;
}
}
if (operation.charAt(y) == ('+'))
{
StringTokenizer c = new StringTokenizer(operation,"+");
double num1 = Double.parseDouble(c.nextToken());
double num2 = Double.parseDouble(c.nextToken());
System.out.println(dec.format(num1+num2));
}
else if (operation.charAt(y) == ('-'))
{
StringTokenizer c = new StringTokenizer(operation,"-");
double num1 = Double.parseDouble(c.nextToken());
double num2 = Double.parseDouble(c.nextToken());
System.out.println(dec.format(num1-num2));
}
else if (operation.charAt(y) == ('*'))
{
StringTokenizer c = new StringTokenizer(operation,"*");
double num1 = Double.parseDouble(c.nextToken());
double num2 = Double.parseDouble(c.nextToken());
System.out.println(dec.format(num1*num2));
}
else if (operation.charAt(y) == ('/'))
{
StringTokenizer c = new StringTokenizer(operation,"/");
double num1 = Double.parseDouble(c.nextToken());
double num2 = Double.parseDouble(c.nextToken());
System.out.println(dec.format(num1/num2));
}
else if (y==0)
{
System.out.println("NaN");
}
}
}
}
#include<iostream>
#include<math.h>
#include<sstream>
using namespace std;
int main()
{
int num[10];
string input;
int counter = 0;
getline(cin,input);
stringstream ss(input);
while(ss>>num[counter]&&counter <10)
{
counter++;
}
for(int j=counter-1;j>0;j--)
{
for(int d=0;d<j;d++)
{
num[d]=abs(num[d+1]-num[d]);
cout<<num[d]<<" ";
}
if(j!=1)
cout<<endl;
}
return 0;
}
import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;
public class PrimeNumber {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int num = 0;
int ans = 0;
int count = 0;
int c = 0;
LinkedList<Integer> alist = new LinkedList<Integer>();
LinkedList<String> blist = new LinkedList<String>();
while (c < n) {
alist.clear();
count = 0;
num = sc.nextInt();
for (int i = 1; i <= num; i++) {
ans = num % i;
if (ans == 0) {
count++;
if (i != 1)
alist.add(i);
}
}
if (count == 2) {
//System.out.println("Prime");
blist.add("Prime");
} else { // not prime
if (num != 1)
//System.out.println(Collections.min(alist));
blist.add(Collections.min(alist).toString());
}
c++;
}
for (int j = 0 ; j < n ; j++) {
System.out.println(blist.get(j));
}
}
}
array = [int(x) for x in input().split(' ')]
diff = int(input())
pair = []
array = sorted(array)
for i in range(len(array)-1):
for j in range(i + 1, len(array), 1):
dist = abs(array[i] - array[j])
if dist == diff:
pair.append((array[i], array[j]))
if len(pair) == 0:
print('No Pair Found')
else:
s = ''
# k = 0
for k, (l, r) in enumerate(pair):
s += '({}, {})'.format(l, r)
if k != len(pair) - 1:
s += ', '
print('Pair Found: {}'.format(s))
import java.util.Scanner;
public class J {
public static void main(String args[]){
Scanner input = new Scanner(System.in);
int n= input.nextInt();
int height = input.nextInt();
int days= input.nextInt();
int [] trees = new int[n];
for(int i=0;i<trees.length;i++){
trees[i]=0;
}
for (int i=0;i<days;i++){
int initial= input.nextInt();
int last = input.nextInt();
int growth =input.nextInt();
for (int j=initial-1;j<last;j++){
trees[j]+=growth;
if(trees[j]>=height){
trees[j]-=height;
}
}
System.out.println(check(trees));
}
}
public static int check(int [] array){
int tent=1;
for (int i=0;i<array.length-1;i++){
if(array[i]!=array[i+1]){
tent++;
}
}
return tent;
}
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
char s[10000];
int diff;
cin.getline(s, 9999);
cin >> diff;
char *token = strtok(s, " ");
vector<int> v;
while(token)
{
v.push_back(atoi(token));
token = strtok(NULL, " ");
}
sort(v.begin(), v.end());
vector<string> v2;
for(int i=1 ;i<v.size(); i++)
{
for(int j=0; j<i; j++)
{
if(v[i] - v[j] == diff)
{
string temp = "(" + to_string(v[j]) + "," + to_string(v[i]) + ")";
v2.push_back(temp);
}
}
}
if(v2.size() == 0)
cout << "No Pair Found";
else
{
cout << "Pair found: ";
for(int i=0; i<v2.size(); i++)
{
cout << v2[i];
if(i != v2.size()-1)
cout << ", ";
}
}
}
#include<iostream>
#include<sstream>
using namespace std;
int main()
{
int num[10];
string input;
int counter = 0;
getline(cin,input);
stringstream ss(input);
while(ss>>num[counter]&&counter <10)
{
counter++;
}
int diff;
cin>>diff;
int a,b;
bool found =true;
bool first = true;
for(int i=0;i<counter;i++)
{
for(int j=0;j<counter;j++)
{
if(i==j)continue;
a=num[i];
b=num[j];
if(a-b==diff&&b<=a){
if(found)
cout<<"Pair Found: ";
found = false;
if(!first)cout<<", ";
cout<<"("<<b<<", "<<a<<")";
first=false;
}
}
}
if(found)
{
cout<<"No Pair Found";
}
return 0;
}
#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;
int main()
{
unsigned long long int n, y;
cout << n;
cin >> n >> y;
unsigned long long int total, g;
cin >> g;
total += g;
}
total = total/y;
if(total%y>0) total++;
cout << total;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
double operation,A,B,T;
char O;
cin>>T;
for(int i=1;i<=T;++i)
{
if (T>=1 && T<=100)
{
cout<<"Enter two number :"<<endl;
cin>>A>>B;
cout<<"Enter operation (+,-,/,*):"<<endl;
cin>>O;
if((1<=A<=10000)&&(1<=B<=10000))//A anb B cannot be negative
{
if(O=='+')
{
operation=A+B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else if (O=='-')
{
operation=A-B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else if(O=='*')
{
operation=A*B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else if(O=='/')
{
operation=A/B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else
{
cout<<"NaN";
}
}
}
}
}
wrong-answer
) (Time Submission : 13:11) (Problem :D - Smart Garbage Disposal System
)s = 0
r = 0
n, b = map(int, input().strip().split(" "))
G = [int(x) for x in input().strip().split(" ")]
for i in range(n):
g = G[i]
g += r
if i > 0 and g < b and g > 0:
s += 1
r = 0
else:
s += g //b
r = g % b
if n-1-i == 0 and r > 0:
s +=1
print(s)
6
Nama saya Ariff Yasri.
Saya suka makan nasi dan sambal ayam.
Everyday I eat apple.
The reason I eat apple because I love it so much.
No pain, no gain.
There is always "someone" who smarter than you, just a matter of time you will surpass them (by ariff).
#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;
int main()
{
unsigned long long int n, y;
cin >> n >> y;
unsigned long long int total, g;
for(int i=0; i<n;i++)
{
cin >> g;
total += g;
}
total = total/y;
if(total%y>0) total++;
cout << total;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
double operation,A,B,T;
char O;
cin>>T;
for(int i=1;i<=T;++i)
{
if (T>=1 && T<=100)
{
cout<<"Enter two number :"<<endl;
cin>>A>>B;
cout<<"Enter operation (+,-,/,*):"<<endl;
cin>>O;
if((1<=A<=10000)&&(1<=B<=10000))//A anb B cannot be negative
{
if(O=='+')
{
operation=A+B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else if (O=='-')
{
operation=A-B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else if(O=='*')
{
operation=A*B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else if(O=='/')
{
operation=A/B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else
{
cout<<"NaN";
}
}
}
}
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
char s[10000];
int diff;
cin.getline(s, 9999);
cin >> diff;
char *token = strtok(s, " ");
vector<int> v;
while(token)
{
v.push_back(atoi(token));
token = strtok(NULL, " ");
}
sort(v.begin(), v.end());
vector<string> v2;
for(int i=1 ;i<v.size(); i++)
{
for(int j=0; j<i; j++)
{
if(v[i] - v[j] == diff)
{
string temp = "(" + to_string(v[j]) + ", " + to_string(v[i]) + ")";
v2.push_back(temp);
}
}
}
if(v2.size() == 0)
cout << "No Pair Found";
else
{
cout << "Pair found: ";
for(int i=0; i<v2.size(); i++)
{
cout << v2[i];
if(i != v2.size()-1)
cout << ", ";
}
}
}
line=input()
ex=line.split()
ex = [int(x) for x in ex]
n=int(input())
ans=""
ex.sort()
for i in range(len(ex)-1):
for j in range(i+1,len(ex)):
if ex[j]-ex[i]==n:
ans+="("+str(ex[i])+","+str(ex[j])+"),"
# print(str(ex[i])+","+str(ex[j]))
if len(ans)==0:
print("No Pair Found")
else:
print("Pair Found: "+ans[:-1])
#include<iostream>
#include<sstream>
using namespace std;
int main()
{
int num[10];
string input;
int counter = 0;
getline(cin,input);
stringstream ss(input);
while(ss>>num[counter]&&counter <10)
{
counter++;
}
if(counter<=2||counter>=10)return 1;
int diff;
cin>>diff;
int a,b;
bool found =true;
bool first = true;
for(int i=0;i<counter;i++)
{
for(int j=0;j<counter;j++)
{
if(i==j)continue;
a=num[i];
b=num[j];
if(a-b==diff&&b<=a){
if(found)
cout<<"Pair Found: ";
found = false;
if(!first)cout<<", ";
cout<<"("<<b<<", "<<a<<")";
first=false;
}
}
}
if(found)
{
cout<<"No Pair Found";
}
return 0;
}
t=int(input())
for _ in range(t):
c=int(input())
if(c==2,5,7):
print('Prime')
elif(c%2==0):
print(2)
elif(c%5==0):
print(5)
elif(c%7==0):
print(7)
else:
print('Prime')
s = 0
r = 0
n, b = map(int, input().strip().split(" "))
G = [int(x) for x in input().strip().split(" ")]
for i in range(n):
g = G[i]
g += r
if i > 0 and g <= b and r > 0 and g > 0:
s += 1
r = 0
else:
s += g //b
r = g % b
if n-1-i == 0 and r > 0:
s +=1
print(s)
#include<iostream>
using namespace std;
int main()
{
int t, b;
cin>>t;
int arr[t];
for (int m = 0; m < t; m++)
{
cin>>arr[m];
}
cout<<"\n";
for (int m = 0; m < t; m++)
{
for ( int i = 2; i < 10000; i++)
{
if (( arr[m] % i == 0 ) && ( arr[m]!=i ))
{
b = i;
break;
}
}
if (arr[m]==0)
cout<<0<<"\n";
else if ( b == 0)
{
cout<<"Prime";
cout<<"\n";
}
else
{
cout<<b;
cout<<"\n";
}
b = 0;
}
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int n, q;
cin >> n >> q;
int disp[n];
int count = 0, trash = 0;
for(int x = 0; x < n; x++)
{
cin >> disp[x];
trash += disp[x];
if(x != (n - 1))
{
if(trash < q)
if(x > 0)
count++;
else
{
while(trash >= q)
{
trash -= q;
count ++;
}
}
}
else
{
while(trash > 0)
{
trash -= q;
count ++;
}
}
}
cout << count << endl;
}
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int T;
cin >> T;
char o;
float a, b;
for (int i = 0; i < T; i++)
{
cin>>a>>o>>b;
if (o == '+')
cout << setprecision(2) << fixed << a + b << endl;
else if (o == '-')
cout << setprecision(2) << fixed << a - b << endl;
else if (o == '*')
cout << setprecision(2) << fixed << a * b << endl;
else if (o == '/')
{
if (b == 0)
cout << "NaN" << endl;
else
cout << setprecision(2) << fixed << a / b << endl;
}
else
cout << "NaN" << endl;
}
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
double operation,A,B,T;
char O;
cin>>T;
for(int i=1;i<=T;++i)
{
if (T>=1 && T<=100)
{
cout<<"Enter two number :"<<endl;
cin>>A>>B;
cout<<"Enter operation (+,-,/,*):"<<endl;
cin>>O;
if((A>=1&&A<=10000)&&(B>=1&&B<=10000))
{
if(O=='+')
{
operation=A+B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else if (O=='-')
{
operation=A-B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else if(O=='*')
{
operation=A*B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else if(O=='/')
{
operation=A/B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else
{
cout<<"NaN";
}
}
}
}
}
line=input()
ex=line.split()
ex = [int(x) for x in ex]
n=int(input())
ans=""
ex.sort()
for i in range(len(ex)-1):
for j in range(i+1,len(ex)):
if ex[j]-ex[i]==n:
ans+="("+str(ex[i])+", "+str(ex[j])+"), "
# print(str(ex[i])+","+str(ex[j]))
if len(ans)==0:
print("No Pair Found")
else:
print("Pair Found: "+ans[:-2])
#include<bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sf(x) scanf("%d\n", &x)
#define pf(x) printf("%d\n", &x)
#define all(x) x.begin(), x.end
#define fill(a,x)memset(a,x,sizeof a)
#define size_a(a)sizeof(a) / sizeof(a[0])
#define dbg(x) cerr <<(#x) << "is" <<x<<'\n'
#define repi(i,a,n) for (int i = (int)a;i<(int)n;++i)
#define repll(i,a,n) for (int i = (ll)a;i<(ll)n;++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef vector<ii>vii;
typedef vector<int>vi;
// Global Variable Declaration
double a,b;
char o;
int T;
int main(){
int N, noxbaru;
double sumx = 0, sumy = 0, sumbu = 0, sumbb = 0, newb, newa, x, y, ybaru[10], xbaru;
cin >> N;
double arr[N][2];
for(int i = 0 ; i < N; ++i){
cin >> arr[i][0];
cin >> arr[i][1];
sumx += arr[i][0];
sumy += arr[i][1];
}
x = sumx/N;
y = sumy/N;
for(int i = 0; i < N; ++i){
sumbu += (arr[i][0] - x) * (arr[i][1] - y);
sumbb += (arr[i][0] - x) * (arr[i][0] - x);
}
newb = sumbu/sumbb;
newa = y - newb * x;
cin >> noxbaru;
for(int i = 0; i < noxbaru; ++i){
cin >> xbaru;
ybaru[i] = newa + (newb * xbaru);
}
cout <<fixed<<setprecision(4)<< newb << " " <<fixed<<setprecision(4)<< newa << endl;
for(int i = 0; i < noxbaru; ++i){
cout <<fixed<<setprecision(4)<<ybaru[i] << endl;
}
return 0;
}
#include<iostream>
#include<sstream>
using namespace std;
int main()
{
int num[10];
string input;
int counter = 0;
getline(cin,input);
stringstream ss(input);
while(ss>>num[counter]&&counter <10)
{
counter++;
}
if(counter<1||counter>9)
{
cout<<"No Pair Found";
return 0;
}
int diff;
cin>>diff;
int a,b;
bool found =true;
bool first = true;
for(int i=0;i<counter;i++)
{
for(int j=0;j<counter;j++)
{
if(i==j)continue;
a=num[i];
b=num[j];
if(a-b==diff&&b<=a){
if(found)
cout<<"Pair Found: ";
found = false;
if(!first)cout<<", ";
cout<<"("<<b<<", "<<a<<")";
first=false;
}
}
}
if(found)
{
cout<<"No Pair Found";
}
return 0;
}
#include <iostream>
using namespace std;
int main ()
{
bool isPrime=true;
int test;
cin>>test;
int notprime;
int n[test];
for(int j=0;j<test;j++){
cin>>n[j];
for(int i=2;i<=n[j]/2;++i){
if(n[j]%i==0)
{
isPrime=false;
if(n[j]%2==0)
notprime=2;
else if(n[j]%3==0)
notprime=3;
else if(n[j]%5==0)
notprime=5;
else if(n[j]%7==0)
notprime=7;
else if(n[j]%11==0)
notprime=11;
else if(n[j]%13==0)
notprime=13;
else if(n[j]%17==0)
notprime=17;
else if(n[j]%19==0)
notprime=19;
else if(n[j]%23==0)
notprime=23;
}
}
if(isPrime)
cout<<"Prime"<<endl;
else
cout<<notprime<<endl;
}
return 0;
}
temp = input()
t = temp.split(' ')
r = int(t[0])
k = int(t[1])
days = int(t[2])
arr = list()
for i in range(r):
arr.append(0);
for i in range(days):
string = input()
t = string.split(' ')
start = int(t[0])-1
end = int(t[1])
growth = int(t[2])
for i in range(start,end):
arr[i] = arr[i] + growth
if arr[i] >= k:
arr[i] = arr[i] - k
count = 0
current = -1
for i in arr:
if current == -1:
current = i
count = count + 1
continue
if current == i:
continue
else:
count = count + 1
current = i
print(count)
import java.util.Arrays;
import java.util.Scanner;
public class a {
public static void main(String[] args){
Scanner sc2 = new Scanner(System.in);
String line = sc2.nextLine();
String[] array = line.split("\\W+");
int[] array2 = new int[array.length];
for(int i=0;i<array.length;i++){
array2[i] = Integer.parseInt(array[i]);
}
int difference = sc2.nextInt();
StringBuilder sb = new StringBuilder();
Arrays.sort(array2);
for(int i=0;i<array.length;i++){
if(i!=array.length-1){
int num1 = Integer.parseInt(array[i]);
int num2 = Integer.parseInt(array[i+1]);
if(num2-num1==difference){
if(sb.length()==0){
sb.append("("+String.valueOf(num1)+", "+String.valueOf(num2)+")");
}else{
sb.append(", ("+String.valueOf(num1)+", "+String.valueOf(num2)+")");
}
}
}
}
if(sb.length()>0){
System.out.print("Pair Found: "+sb.toString());
}else{
System.out.print("No Pair Found");
}
}
}
#include<iostream>
#include<math.h>
using namespace std;
string d2b(int n){
string b = "";
if(n == 0){
b = "0" + b;
}
while(n>0){
if(n%2 == 0){
b = "0" + b;
}else{
b = "1" + b;
}
n /= 2;
}
return b;
}
int main(){
int T, n;
cin >> T;
for(int i=0;i<T;i++){
cin >> n;
int t = pow(2,n);
int c=0;
for(int j=0;j<t;j++){
string b = d2b(j);
int zero =0;
for(int j =0;j<b.length();j++){
for(int k=0;k<n-b.length();k++){
b = "0" + b;
}
if(b[j] == '0' ){
zero++;
}
else if(b[j] == '1' ) {
zero = 0;
}
if(zero == 2){
break;
}
}
if(zero != 2){
c++;
}
}
cout << c << endl;
}
}
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] inputs = br.readLine().split(" ");
String[] days = br.readLine().split(" ");
long c = Long.parseLong(inputs[1]);
long extra = 0, num = 0;
for (int i = 0; i < days.length ; i+= 2) {
double g = 0, n = 0;
if(i + 1 == days.length){
g += Integer.parseInt(days[i]) - extra;
}else{
g += Integer.parseInt(days[i]) + Integer.parseInt(days[i + 1]) - extra;
}
n = Math.ceil(g /c);
num += n;
extra = (long) (c * n - g);
}
System.out.println(num);
}
}
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int test;
cin>>test;
for(int i=0;i<test;i++)
{
float a,b;
char sign;
cin>>a>>sign>>b;
if(sign=='+')
cout<<fixed<<setprecision(2)<<a+b<<endl;
else if(sign=='-')
cout<<fixed<<setprecision(2)<<a-b<<endl;
else if(sign=='*')
cout<<fixed<<setprecision(2)<<a*b<<endl;
else if(sign=='/')
{
if(b==0)
cout<<"NaN"<<endl;
else
cout<<fixed<<setprecision(2)<<a/b<<endl;
}
else
cout<<"NaN"<<endl;
}
return 0;
}
n,q=map(int,input().split())
sensor=[]
for _ in range(n):
sensor.append(list(map(int,input().split())))
for _ in range(q):
reading=int(input())
j=n//2
left=0
right=n-1
index=None
test=0
if reading<sensor[0][0]:
print(-1,-1,sensor[0][0])
continue
if reading>sensor[n-1][0]:
print(sensor[n-1][1],sensor[n-1][0],-1)
continue
while left<right-1:
if sensor[j][0]==reading:
index=j
break
elif sensor[j][0]<reading:
left=j+1
index=j+1
else:
right=j-1
index=j-1
j=(right-left+1)//2
print(sensor[index][1],sensor[index][0],sensor[index+1][0])
import java.util.*;
public class QG2{
public static void main(String arg[])
{
Scanner input = new Scanner(System.in);
String num = input.nextLine();
String line[] = num.split(" ");
int num2[]= new int[line.length];
for(int i=0; i<line.length; i++)
{
num2[i] = Integer.parseInt(line[i]);
}
int k=1;
for(int i=0; i<num2.length; i++)
{
for(int j=0; j<num2.length-k;j++)
{
int ans=1;
if(num2[j]<num2[j+1])
{
ans = num2[j+1] - num2[j];
System.out.print(ans+" ");
}
else if(num2[j]>num2[j+1])
{
ans = num2[j] - num2[j+1];
System.out.print(ans+" ");
}
num2[j]=ans;
}
System.out.println();
k++;
}
}
}
import math
l = int(input())
h = int(input())
d = int(input())
def removeSame(z):
dik = dict()
for x in z:
if not x in dik:
dik[x] = 0
return len(dik)
day = []
for i in range(l):
day.append(0)
for i in range(d):
f = int(input())
f = f -1
t = int(input())
p = int(input())
for x in range(f,t,1):
tent = 1
day[x] += p
if day[x] >= h :
tent = (day[x] / h)
tent = math.floor(tent)+ 1
day[x] = abs(day[x] - (h* (tent-1)))
tent = removeSame(day)
print(tent)
n,q=map(int,input().split())
sensor=[]
for _ in range(n):
sensor.append(list(map(int,input().split())))
sensor=sorted(sensor)
for _ in range(q):
reading=int(input())
j=n//2
left=0
right=n-1
index=None
test=0
if reading<sensor[0][0]:
print(-1,-1,sensor[0][0])
continue
if reading>sensor[n-1][0]:
print(sensor[n-1][1],sensor[n-1][0],-1)
continue
while left<right-1:
if sensor[j][0]==reading:
index=j
break
elif sensor[j][0]<reading:
left=j+1
index=j+1
else:
right=j-1
index=j-1
j=(right-left+1)//2
print(sensor[index][1],sensor[index][0],sensor[index+1][0])
import java.util.*;
import java.text.DecimalFormat;
public class QF3{
public static void main(String arg[])
{
Scanner input = new Scanner(System.in);
int loop=input.nextInt();
input.nextLine();
for(int i=0; i< loop; i++)
{
String word=input.nextLine();
boolean found=false;
for(int j=0; j<word.length(); j++)
{
if(word.charAt(j)=='+' || word.charAt(j)=='-' ||word.charAt(j)=='*' ||word.charAt(j)=='/' )
{
/*if(word.charAt(j)=='+')
{
String m[]= word.split("+");
double a = Double.parseDouble(m[0]);
double b = Double.parseDouble(m[1]);
double z=a+b;
System.out.println(new DecimalFormat("0.00").format(z));
}
if(word.charAt(j)=='-')
{
String m[]= word.split("-");
double a = Double.parseDouble(word.substring());
double b = Double.parseDouble(m[1]);
System.out.println(new DecimalFormat("0.00").format(a-b));
}
if(word.charAt(j)=='*')
{
String m[]= word.split("*");
double a = Double.parseDouble(m[0]);
double b = Double.parseDouble(m[1]);
System.out.println(new DecimalFormat("0.00").format(a*b));
}
if(word.charAt(j)=='/')
{
String m[]= word.split("/");
double a = Double.parseDouble(m[0]);
double b = Double.parseDouble(m[0]);
System.out.println(new DecimalFormat("0.00").format(a/b));
}*/
found=true;
double a = Double.parseDouble(word.substring(0,j-1));
double b = Double.parseDouble(word.substring(j+1));
if(word.charAt(j)=='+')
{
System.out.println(new DecimalFormat("0.00").format(a+b));
}
else if(word.charAt(j)=='-')
{
System.out.println(new DecimalFormat("0.00").format(a-b));
}
else if(word.charAt(j)=='*')
{
System.out.println(new DecimalFormat("0.00").format(a*b));
}
else if(word.charAt(j)=='/')
{
System.out.println(new DecimalFormat("0.00").format(a/b));
}
break;
}
}
if(found==false)
{
System.out.println("NaN");
}
}
}
}
import math
tc = input()
l,h,d = tc.split()
l = int(l)
h= int(h)
d = int(d)
def removeSame(z):
dik = dict()
for x in z:
if not x in dik:
dik[x] = 0
return len(dik)
day = []
for i in range(l):
day.append(0)
for i in range(d):
temp = input()
f, t, p = temp.split()
f = int(f)
f = f -1
t = int(t)
p = int(p)
for x in range(f,t,1):
tent = 1
day[x] += p
if day[x] >= h :
tent = (day[x] / h)
tent = math.floor(tent)+ 1
day[x] = abs(day[x] - (h* (tent-1)))
tent = removeSame(day)
print(tent)
#include<iostream>
#include<math.h>
using namespace std;
string d2b(int n){
string b = "";
if(n == 0){
b = "0" + b;
}
while(n>0){
if(n%2 == 0){
b = "0" + b;
}else{
b = "1" + b;
}
n /= 2;
}
return b;
}
int main(){
int T, n;
cin >> T;
for(int i=0;i<T;i++){
cin >> n;
int t = pow(2,n);
int c=0;
for(int j=0;j<t;j++){
string b = d2b(j);
int zero =0;
while(b.length()<n){
b = "0" + b;
}
for(int j =0;j<b.length();j++){
if(b[j] == '0' ){
zero++;
}
else if(b[j] == '1' ) {
zero = 0;
}
if(zero == 2){
break;
}
}
if(zero != 2){
c++;
}
}
cout << c << endl;
}
}
while True:
try:
line1 = input().split()
line2 = input()
q = int(line2)
n = [int(i) for i in line1]
result = []
for i in range(len(n)):
for j in range(len(n)):
if i != j:
if n[j] - n[i] == q:
result.append((n[i], n[j]))
# print(result)
if len(result) != 0:
print('Pair Found: ', end='')
print(', '.join([str(r) for r in result]))
# print()
# print(result)
else:
print('No Pair Found')
except Exception as e:
print(e)
break
#include <cstdio>
#include <cstring>
using namespace std;
int main() {
long int n, k, d, a, b, h, i, j;
scanf("%ld %ld %ld", &n, &k, &d);
long int arr[n];
memset(arr, 0, sizeof arr);
while(d--) {
scanf("%ld %ld %ld", &a, &b, &h);
for(i = a - 1; i < b; i++)
arr[i] = (arr[i] + h) % k;
j = 1;
for(i = 0; i < n - 1; i++)
if(arr[i + 1] != arr[i])
j++;
printf("%d\n", j);
}
return 0;
}
def recurr(length):
if length==1:
return 2
elif length ==2:
return 3
else:
return recurr(length-1)+recurr(length-2)
testcase = int(input())
for x in range(testcase):
length = int(input())
print(recurr(length))
#include<iostream>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
if(a<1||b<1||a>20000||b>1000000000)
{
cout<<"out of range";
return 1;
}
int garbage= 0;
int day;
for(int i=0;i<a;i++)
{
cin>>day;
if(day<1||day>1000000000)
{
cout<<"out of range";
return 1;
}
garbage +=day;
}
if((double)garbage/b>(int)garbage/b)
{
cout<<garbage/b + 1;
}
else
cout<<garbage/b;
return 0;
}
import java.util.*;
public class QG{
public static void main(String arg[])
{
Scanner input = new Scanner(System.in);
String num = input.nextLine();
String line[] = num.split(" ");
int num2[]= new int[line.length];
for(int i=0; i<line.length; i++)
{
num2[i] = Integer.parseInt(line[i]);
}
int k=1;
for(int i=0; i<num2.length; i++)
{
for(int j=0; j<num2.length-k;j++)
{
int ans=1;
if(num2[j]<=num2[j+1])
{
ans = num2[j+1] - num2[j];
System.out.print(ans+" ");
}
else if(num2[j]>=num2[j+1])
{
ans = num2[j] - num2[j+1];
System.out.print(ans+" ");
}
num2[j]=ans;
}
System.out.println();
k++;
}
}
}
#include<iostream>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
if(a<1||b<1||a>20000||b>1000000000)
{
cout<<"out of range";
return 0;
}
int garbage= 0;
int day;
for(int i=0;i<a;i++)
{
cin>>day;
if(day<1||day>1000000000)
{
cout<<"out of range";
return 0;
}
garbage +=day;
}
if((double)garbage/b>(int)garbage/b)
{
cout<<garbage/b + 1;
}
else
cout<<garbage/b;
return 0;
}
#include<iostream>
#include<math.h>
using namespace std;
string d2b(int n, int N){
string b = "";
//if(n == 0){
// b = "0" + b;
// }
while(n>0){
if(n%2 == 0){
b = "0" + b;
}else{
b = "1" + b;
}
n /= 2;
}
while(b.length() != N)
b = "0" + b;
return b;
}
int main(){
int T, n;
cin >> T;
for(int i=0;i<T;i++){
cin >> n;
int t = pow(2,n);
int c=0;
for(int j=0;j<t;j++){
string b = d2b(j, n);
int zero =0;
while(b.length()<n){
b = "0" + b;
}
for(int j =0;j<b.length();j++){
if(b[j] == '0' ){
zero++;
}
else if(b[j] == '1' ) {
zero = 0;
}
if(zero == 2){
break;
}
}
if(zero != 2){
c++;
}
}
cout << c << endl;
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
public class E {
static char[][] maze;
static int N, M;
static String answer;
static int mincost = Integer.MAX_VALUE;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
M = Integer.parseInt(st.nextToken());
maze = new char[N][M];
for(int i=0;i<N;i++){
maze[i]=br.readLine().toCharArray();
}
boolean[][] visited = new boolean[N][M];
for(int i=0;i<N;i++){
for(int j=0;j<maze[i].length;j++){
if(maze[i][j]=='D'){
solve(i,j,"", 0, visited);
}
}
}
System.out.println(answer);
}
public static void solve(int i, int j, String ans, int cost, boolean[][] visited){
if(valid(i,j-1 )&& !visited[i][j-1]){
char c = maze[i][j-1];
visited[i][j-1] = true;
if(c=='_'){
solve(i,j-1, ans+"L", cost+1, visited);
}
else if(c=='S'){
solve(i,j-1, ans+"L", cost+5, visited);
}
else if(c=='C'){
if(cost<mincost){
mincost=cost;
answer = ans+"L";
}
}
visited[i][j-1] = false;
}
if(valid(i,j+1)&& !visited[i][j+1]){
char c = maze[i][j+1];
visited[i][j+1] = true;
if(c=='_'){
solve(i,j+1, ans+"R", cost+1, visited);
}
else if(c=='S'){
solve(i,j+1, ans+"R", cost+5, visited);
}
else if(c=='C'){
if(cost<mincost){
mincost=cost;
answer = ans+"R";
}
}
visited[i][j+1] = false;
}
if(valid(i-1,j)&& !visited[i-1][j]){
char c = maze[i-1][j];
visited[i-1][j] = true;
if(c=='_'){
solve(i-1,j, ans+"U", cost+1, visited);
}
else if(c=='S'){
solve(i-1,j, ans+"U", cost+5, visited);
}
else if(c=='C'){
if(cost<mincost){
mincost=cost;
answer = ans+"U";
}
}
visited[i-1][j] = false;
}if(valid(i+1,j)&& !visited[i+1][j]){
char c = maze[i+1][j];
visited[i+1][j] = true;
if(c=='_'){
solve(i+1,j, ans+"D", cost+1, visited);
}
else if(c=='S'){
solve(i+1,j, ans+"D", cost+5, visited);
}
else if(c=='C'){
if(cost<mincost){
mincost=cost;
answer = ans+"D";
}
}
visited[i+1][j] = false;
}
}
public static boolean valid(int i, int j){
return i>=0&&i<N&&j>=0&&j<M;
}
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
int T;
double operation,A,B;
char O;
cin>>T;
for(int i=1;i<=T;++i)
{
if (T>=1 && T<=100)
{
cout<<"Enter two number :"<<endl;
cin>>A>>B;
cout<<"Enter operation (+,-,/,*):"<<endl;
cin>>O;
if((A>=1&&A<=10000)&&(B>=1&&B<=10000))
{
if(O=='+')
{
operation=A+B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else if (O=='-')
{
operation=A-B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else if(O=='*')
{
operation=A*B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else if(O=='/')
{
operation=A/B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else
{
cout<<"NaN";
}
}
else
{
cout<<"NaN";
}
}
}
}
#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;
bool prime(int n)
{
if (n<2) return false;
if (n<=3) return true;
if (!(n%2)|| !(n%3)) return false;
for (int i=5; i*i<=n; i+=6)
if (!(n%1) || !(n%(i+2))) return false;
return true;
}
int factor(int n)
{
int a;
if (n%2==0)
return 2;
for (a=3;a<=sqrt(n);a=a+2)
{
if (n%a==0)
return a;
}
return n;
}
int main()
{
int x;
cin >> x;
for(int i = 0; i < x; i++)
{
int num;
cin >> num;
if(prime(num))
cout << "Prime" << endl;
else
cout << factor(num) << endl;
}
}
/*
int num;
while (num>1)
{
r = factor(num);
printf("%d", r);
num /=r;
}
*/
n,b=map(int,input().split())
a=list(map(int,input().split()))
print(-(-sum(a)//b))
import java.util.*;
import java.text.DecimalFormat;
public class QF{
public static void main(String arg[])
{
Scanner input = new Scanner(System.in);
int loop=input.nextInt();
input.nextLine();
for(int i=0; i< loop; i++)
{
String word=input.nextLine();
boolean found=false;
for(int j=0; j<word.length(); j++)
{
if(word.charAt(j)=='+' || word.charAt(j)=='-' ||word.charAt(j)=='*' ||word.charAt(j)=='/' )
{
found=true;
double a = Double.parseDouble(word.substring(0,j-1));
double b = Double.parseDouble(word.substring(j+1));
if(word.charAt(j)=='+')
{
System.out.println(new DecimalFormat("0.00").format(a+b));
}
else if(word.charAt(j)=='-')
{
System.out.println(new DecimalFormat("0.00").format(a-b));
}
else if(word.charAt(j)=='*')
{
System.out.println(new DecimalFormat("0.00").format(a*b));
}
else if(word.charAt(j)=='/')
{
if(b==0)
{
found=false;
}
else
System.out.println(new DecimalFormat("0.00").format(a/b));
}
break;
}
}
if(found==false)
{
System.out.println("NaN");
}
}
}
}
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main() {
int n;
cin >> n;
double x[n];
double y[n];
for(int i =0; i<n; i++){
cin >> x[i] >> y[i];
}
double avg_x = 0;
double avg_y = 0;
for(int i=0;i<n;i++){
avg_x += x[i];
avg_y += y[i];
//cout<<"done add";
}
avg_x /= n;
avg_y /= n;
//cout <<"test div";
double sum1=0;
for(int i=0;i<n;i++){
sum1+= (x[i]-avg_x)*(y[i]-avg_y);
}
double sum2=0;
for(int i=0;i<n;i++){
sum2+= (x[i]-avg_x)*(x[i]-avg_x);
}
double beta = sum1 / sum2;
double alpha = avg_y - beta*avg_x;
printf("%.4f %.4f\n", beta, alpha);
int b;
cin>>b;
double xp[b];
for(int i=0; i<b;i++){
cin>>xp[i];
printf("%.4f\n",alpha+beta*xp[i]);
}
return 0;
}
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int tc;
double num1, num2,ans;
char operation;
cin>>tc;
for(int i=0 ; i<tc ; i++)
{
cin>>num1>>operation>>num2;
if(operation == '/' && num2 == 0)
if(num1 == 0)
printf("%.2f",0);
else
cout<<"NaN"<<endl;
else if(operation == '+'){
ans = num1 + num2;
printf("%.2f",ans);
cout<<endl;}
else if(operation == '-'){
ans = num1 - num2;
printf("%.2f",ans);
cout<<endl;}
else if(operation == '*'){
ans = num1 * num2;
printf("%.2f",ans);
cout<<endl;}
else if(operation == '/'){
ans = num1 / num2;
printf("%.2f",ans);
cout<<endl;}
}
}
#include<iostream>
using namespace std;
int main()
{
int a,b;
do
{
cin>>a>>b;
}while(a<1||b<1||a>20000||b>1000000000);
int garbage= 0;
int day;
for(int i=0;i<a;i++)
{
do
{
cin>>day;
}while(day<1||day>1000000000);
garbage +=day;
}
if((double)garbage/b>(int)garbage/b)
{
cout<<garbage/b + 1;
}
else
cout<<garbage/b;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
int T;
double operation,A,B;
char O;
cout<<"Enter the number of test cases :";
cin>>T;
for(int i=1;i<=T;++i)
{
if (T>=1 && T<=100)
{
cout<<"Enter two number :"<<endl;
cin>>A>>B;
cout<<"Enter operation (+,-,/,*):"<<endl;
cin>>O;
if((A>=1&&A<=10000)&&(B>=1&&B<=10000))
{
if(O=='+')
{
operation=A+B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else if (O=='-')
{
operation=A-B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else if(O=='*')
{
operation=A*B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else if(O=='/')
{
operation=A/B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else
{
cout<<"NaN"<<endl;
}
}
else
{
cout<<"NaN"<<endl;
}
}
}
}
dict = {}
def recurr(length):
if length==1:
return 2
elif length ==2:
return 3
else:
if (length-1) not in dict.keys():
dict[length-1] = recurr(length-1)
if (length-2) not in dict.keys():
dict[length-2] = recurr(length-2)
return dict[length-1] + dict[length-2]
testcase = int(input())
for x in range(testcase):
length = int(input())
print(recurr(length))
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ll n,b;cin>>n>>b;
ll ans=0,l=0;
for(int i=0;i<n;i++){
ll tm;cin>>tm;
ans+=ceil(l*1.0/b);
tm-=l-l%b;
l=0;
// cout<<ans<<" "<<tm<<endl;
if(tm>0){
ans+=tm/b;
l=tm%b;
}
}
cout<<ans<<endl;
}
//package prosolve_im26c4u;
import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.util.regex.Pattern;
public class Main {
public static void main(String args[]) throws IOException {
String input = "a.in";
String output = "a.out";
boolean file = false;
BufferedReader br;
if (file) {
br = new BufferedReader(new FileReader(input));
} else {
br = new BufferedReader(new InputStreamReader(System.in));
}
PrintWriter pr;
if (file) {
pr = new PrintWriter(new FileWriter(output));
} else {
pr = new PrintWriter(System.out);
}
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int q = Integer.parseInt(st.nextToken());
Pair p[] = new Pair[n];
for (int i = 0; i < n; i++) {
st = new StringTokenizer(br.readLine());
int t = Integer.parseInt(st.nextToken());
int x = Integer.parseInt(st.nextToken());
p[i] = new Pair(t, x);
}
Arrays.sort(p);
int min = p[0].t;
int max = p[n - 1].t;
for (int i = 0; i < q; i++) {
int value = Integer.parseInt(br.readLine());
if (value <= min) {
System.out.println(-1 + " " + -1 + " " + min);
} else if (value >= max) {
System.out.println(p[n - 1].x + " " + max + " " + "-1");
} else {
int low = 0;
int high = n - 1;
int leftIndex = -1;
while (low <= high) {
int mid = (low + high) / 2;
if (p[mid].t <= value) {
low = mid + 1;
if (leftIndex == -1) {
leftIndex = mid;
} else {
leftIndex = Math.max(leftIndex, mid);
}
} else {
high = mid - 1;
}
}
System.out.println(p[leftIndex].x + " " + p[leftIndex].t + " " + p[leftIndex + 1].t);
}
}
pr.close();
}
static class Pair implements Comparable<Pair> {
int t = 0;
int x = 0;
Pair(int t, int x) {
this.t = t;
this.x = x;
}
@Override
public int compareTo(Pair p) {
return this.t - p.t;
}
}
}
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] inputs = br.readLine().split(" ");
String[] days = br.readLine().split(" ");
long c = Long.parseLong(inputs[1]);
long extra = 0, num = 0;
for (int i = 0; i < days.length ; i+= 2) {
long g = 0, n = 0;
if(i + 1 == days.length){
g += Integer.parseInt(days[i]) - extra;
}else{
g += Integer.parseInt(days[i]) + Integer.parseInt(days[i + 1]) - extra;
}
n = (long) Math.ceil(g /c);
num += n;
extra = (long) (c * n - g);
}
System.out.println(num);
}
}
#include<iostream>
using namespace std;
int main()
{
cout<<"Hello World!";
}
while True:
try:
line1 = input().split()
line2 = input()
q = int(line2)
n = [int(i) for i in line1]
result = []
for i in range(len(n)):
for j in range(len(n)):
if i != j:
if n[j] - n[i] == q:
result.append((n[i], n[j]))
# print(result)
if len(result) != 0:
print('Pair Found: ', end='')
print(', '.join([str(r) for r in result]))
# print()
# print(result)
else:
print('No Pair Found')
except Exception as e:
# print(e)
break
#include<bits/stdc++.h>
using namespace std;
int main()
{
int T;
double operation,A,B;
char O;
cin>>T;
for(int i=1;i<=T;++i)
{
if (T>=1 && T<=100)
{
cin>>A>>O>>B;
if((A>=1&&A<=10000)&&(B>=1&&B<=10000))
{
if(O=='+')
{
operation=A+B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else if (O=='-')
{
operation=A-B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else if(O=='*')
{
operation=A*B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else if(O=='/')
{
operation=A/B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else
{
cout<<"NaN"<<endl;
}
}
else
{
cout<<"NaN"<<endl;
}
}
}
}
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ll n,b;cin>>n>>b;
ll ans=0,l=0;
for(int i=0;i<n;i++){
ll tm;cin>>tm;
ans+=ceil(l*1.0/b);
tm-=l-l%b;
l=0;
// cout<<ans<<" "<<tm<<endl;
if(tm>0){
ans+=tm/b;
l=tm%b;
}
}
ans+=ceil(l*1.0)/b;
cout<<ans<<endl;
}
#include<bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sf(x) scanf("%d\n", &x)
#define pf(x) printf("%d\n", &x)
#define all(x) x.begin(), x.end
#define fill(a,x)memset(a,x,sizeof a)
#define size_a(a)sizeof(a) / sizeof(a[0])
#define dbg(x) cerr <<(#x) << "is" <<x<<'\n'
#define repi(i,a,n) for (int i = (int)a;i<(int)n;++i)
#define repll(i,a,n) for (int i = (ll)a;i<(ll)n;++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef vector<ii>vii;
typedef vector<int>vi;
// Global Variable Declaration
int n,b;
int g[100005]={};
int main(){
cin>>n>>b;
repi(i,0,n){
cin >> g[i];
}
// dbg(b);
int cnt=0;
repi(i,0,n){
// for(int k=0;k<n;++k)
// dbg(g[k]);
if(g[i]>=b){
cnt++;
g[i+1]+=g[i]-b;
g[i]=0;
}
else{
g[i+1]+=g[i];
}
}
// dbg(cnt);
// dbg(g[n]);
if(g[n]!=0){
cout<<cnt + (g[n-1]/b+ 1)<<endl;
}
else
cout<<cnt<<endl;
return 0;
}
import java.util.*;
class i{
public static void main(String []args){
Scanner sc = new Scanner(System.in);
int line;
for(;;){
System.out.print("Enter amount of numbers, n(0 < n < 51): ");
line = Integer.parseInt(sc.nextLine());
if(line<1 || line>50) System.out.println("\nRe-enter number\n");
else break;
}
Integer[] n = new Integer[line];
for(int i = 0; i<n.length;){
System.out.print("Enter number "+ (i+1) +" n(1 < n < 10,001): ");
n[i] = Integer.parseInt(sc.nextLine());
if(n[i]>10000 || n[i]<2)System.out.print("\nRe-enter number\n");
else i++;
}
System.out.print("\n");
for(int i = 0; i<n.length; i++){
boolean found = false;
int smf = 10000;
for(int j=2; j<n[i];j++){
if(n[i]%j==0){
found = true;
if(j<smf) smf = j;
}
}
if(!found) System.out.println("Prime");
else System.out.println(smf);
}
System.out.print("\n");
}
}
#include <iostream>
using namespace std;
int main()
{
float a, b, ans;
int t;
char o;
cout<<"Enter number of test cases: ";
cin>>t;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
if(t>0 && t<=100)
{
for(int i=0; i<t; i++)
{
ans=0;
cout<<"Enter number A: ";
cin>>a;
cout<<"Enter number B: ";
cin>>b;
cout<<"Enter operation: (+, -, *, /) : ";
cin>>o;
if(o == '+')
{
ans = a + b;
cout<<ans<<endl;
}
else if(o == '-')
{
ans = a - b;
cout<<ans<<endl;
}
else if(o == '*')
{
ans = a * b;
cout<<ans<<endl;
}
else if(o == '/')
{
ans = a / b;
cout<<ans<<endl;
}
else
cout<<"\nNaN";
}
}
return 0;
}
#include<bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sf(x) scanf("%d\n", &x)
#define pf(x) printf("%d\n", &x)
#define all(x) x.begin(), x.end
#define fill(a,x)memset(a,x,sizeof a)
#define size_a(a)sizeof(a) / sizeof(a[0])
#define dbg(x) cerr <<(#x) << "is" <<x<<'\n'
#define repi(i,a,n) for (int i = (int)a;i<(int)n;++i)
#define repll(i,a,n) for (int i = (ll)a;i<(ll)n;++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef vector<ii>vii;
typedef vector<int>vi;
// Global Variable Declaration
ll n,b;
ll g[100005]={};
int main(){
cin>>n>>b;
repi(i,0,n){
cin >> g[i];
}
// dbg(b);
ll cnt=0;
repi(i,0,n){
// for(int k=0;k<n;++k)
// dbg(g[k]);
if(g[i]>=b){
cnt++;
g[i+1]+=g[i]-b;
g[i]=0;
}
else{
g[i+1]+=g[i];
}
}
// dbg(cnt);
// dbg(g[n]);
if(g[n]!=0){
cout<<cnt + (g[n-1]/b+ 1)<<endl;
}
else
cout<<cnt<<endl;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void countTent(vector<int> v)
{
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
cout << v.size() << endl;
}
void potong(vector<int>& v, int maxHeight)
{
for(int i=0; i<v.size(); i++)
{
if(v[i] >= maxHeight)
v[i] -= maxHeight;
}
}
void treeGrows(vector<int>& v, int a, int b, int grow)
{
a--;
b--;
for(int i=a; i<=b; i++)
{
v[i] += grow;
}
}
void printVector(vector<int> v)
{
for(int i : v)
cout << i << " ";
cout << endl;
}
int main()
{
int numTree = 0;
int maxHeight = 0;
int numDays = 0;
cin >> numTree >> maxHeight >> numDays;
vector<int> trees;
for(int i = 0; i < numTree; i++)
trees.push_back(0);
for(int i=0; i< numDays; i++)
{
int a, b, grow;
cin >> a >> b >> grow;
treeGrows(trees, a, b, grow);
potong(trees, maxHeight);
countTent(trees);
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
public class E {
static char[][] maze;
static int N, M;
static String answer;
static int mincost = Integer.MAX_VALUE;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
M = Integer.parseInt(st.nextToken());
maze = new char[N][M];
for(int i=0;i<N;i++){
maze[i]=br.readLine().toCharArray();
}
boolean[][] visited = new boolean[N][M];
for(int i=0;i<N;i++){
for(int j=0;j<maze[i].length;j++){
if(maze[i][j]=='D'){
solve(i,j,"", 0, visited);
}
}
}
System.out.println(answer);
}
public static void solve(int i, int j, String ans, int cost, boolean[][] visited) {
char c = maze[i][j];
if (c == 'C') {
if (cost < mincost) {
mincost = cost;
answer = ans;
}
} else {
if(c=='S'){
cost+=5;
}
if(c=='_'){
cost+=1;
}
if (valid(i, j - 1) && !visited[i][j - 1]) {
if (maze[i][j-1]!='#') {
visited[i][j - 1] = true;
solve(i, j - 1, ans + "L", cost, visited);
visited[i][j - 1] = false;
}
}
if (valid(i, j + 1) && !visited[i][j + 1]) {
if (maze[i][j+1]!='#') {
visited[i][j + 1] = true;
solve(i, j + 1, ans + "R", cost, visited);
visited[i][j + 1] = false;
}
}
if (valid(i - 1, j) && !visited[i - 1][j]) {
if (maze[i-1][j]!='#') {
visited[i - 1][j] = true;
solve(i - 1, j, ans + "U", cost, visited);
visited[i - 1][j] = false;
}
}
if (valid(i + 1, j) && !visited[i + 1][j]) {
if (maze[i+1][j]!='#') {
visited[i + 1][j] = true;
solve(i + 1, j, ans + "D", cost, visited);
visited[i + 1][j] = false;
}
}
}
}
public static boolean valid(int i, int j){
return i>=0&&i<N&&j>=0&&j<M;
}
}
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 330;
int n, k, d;
vector<int> arr[350];
pair<pair<int, ll>, pii> pro[350];
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 350; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
vector<int> tmp;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
tmp.clear();
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC) arr[a][j] += h;
tmp.push_back(arr[a][j] % k);
}
sort(all(tmp));
tmp.resize(unique(all(tmp)) - tmp.begin());
pro[a].F.F = sz(tmp);
pro[a].S.F = arr[a][sz(arr[a]) - 1];
tmp.clear();
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= r % MAGIC) arr[b][j] += h;
tmp.push_back(arr[b][j] % k);
}
sort(all(tmp));
tmp.resize(unique(all(tmp)) - tmp.begin());
pro[b].F.F = sz(tmp);
pro[b].S.S = arr[b][0];
} else {
tmp.clear();
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC && j <= r % MAGIC) arr[a][j] += h;
tmp.push_back(arr[a][j] % k);
}
sort(all(tmp));
tmp.resize(unique(all(tmp)) - tmp.begin());
pro[b].F.F = sz(tmp);
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (j > 0) ans -= (pro[j].S.S % k == pro[j-1].S.F % k);
}
printf("%d\n", ans);
}
return 0;
}
import java.util.*;
class i{
public static void main(String []args){
Scanner sc = new Scanner(System.in);
int line = Integer.parseInt(sc.nextLine());
Integer[] n = new Integer[line];
for(int i = 0; i<n.length;i++){
n[i] = Integer.parseInt(sc.nextLine());
}
System.out.print("\n");
for(int i = 0; i<n.length; i++){
boolean found = false;
int smf = 10000;
for(int j=2; j<n[i];j++){
if(n[i]%j==0){
found = true;
if(j<smf) smf = j;
}
}
if(!found) System.out.println("Prime");
else System.out.println(smf);
}
System.out.print("\n");
}
}
def read():
return map(int, input().strip().split(" "))
n, q = read()
r = []
for i in range(n):
t, x = read()
r.append((t,x))
r = sorted(r, key=lambda k: k[0])
for i in range(q):
a = int(input())
if r[0][0] > a:
print(-1,-1,r[0][0])
elif r[-1][0] < a:
print(r[-1][1], r[-1][0], -1)
else:
# for j in range(n):
# if r[j+1][0] > a:
# print(r[j][1], r[j][0], r[j+1][0])
# break
v, w = 0, len(r)
while True:
m = (v + w) // 2
if a >= r[m][0]:
if a < r[m + 1][0]:
break
v = m + 1
else:
if a >= r[m - 1][0]:
m -= 1
break
w = m - 1
print(r[m][1], r[m][0], r[m + 1][0])
#include<iostream>
using namespace std;
int main(){
int a[6];
cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4]>>a[5];
for(int i = 5; 0<i ;i--)
{
for(int j=0;i>j;j++)
{
a[j]=a[j]-a[j+1];
if(a[j]<0)
{
a[j] = a[j]*(-1);
}
cout<<a[j]<<" ";
}
cout<<"\n";
}
return 0;
}
import java.util.*;
import java.math.*;
public class C
{
public static BigInteger memo[] = new BigInteger[10000];
public static BigInteger fib(int n){
if(n==1||n==2)
return BigInteger.ONE;
if(memo[n]!=null)
return memo[n];
return memo[n] = fib(n-1).add(fib(n-2));
}
public static void main(String []args){
Scanner input = new Scanner(System.in);
int cases = input.nextInt();
for(int x=0; x<cases; x++){
int a = input.nextInt();
System.out.println(fib(a+2));
}
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class C {
static int[] cache = new int[1001];
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int T = Integer.parseInt(br.readLine());
cache[0] = 1;
cache[1] = 2;
cache[2] = 3;
while(T>0){
sb.append(solve(Integer.parseInt(br.readLine())));
sb.append("\n");
T--;
}
System.out.println(sb.toString());
}
public static int solve(int N) {
if (cache[N] != 0) {
return cache[N];
} else {
cache[N]=solve(N - 1) + solve(N - 2);
return cache[N];
}
}
}
tc = int(input())
x = []
sumX =0
y = []
sumY=0
for i in range(tc):
temp = input()
t1,t2 = temp.split()
t1 = float(t1)
sumX += t1
x.append(t1)
t2 = float(t2)
sumY += t2
y.append(t2)
xMean = sumX / len(x)
yMean = sumY / len(y)
sum2 = 0
sum1 = 0
for i in range(tc):
sum1 += (x[i] - xMean)**2
sum2 += (x[i] - xMean) * (y[i] - yMean)
B = sum2/sum1
A = yMean - B*xMean
print("{:.4f} {:.4f}".format(B,A))
pred = int(input())
for _ in range(pred):
xin = float(input())
y = A + B*xin
print("{:.4f}".format(y))
import java.util.*;
import java.io.*;
import java.math.BigInteger;
class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] in = br.readLine().split(" ");
int n = Integer.parseInt(in[0]);
int b = Integer.parseInt(in[1]);
String[] line = br.readLine().split(" ");
int garbage = 0, yesterday = 0;
for (int i = 0; i < n; i++) {
int today = Integer.parseInt(line[i]);
int tGarbage = (today + yesterday) / b;
if (tGarbage == 0 && yesterday > 0) {
yesterday = 0;
tGarbage++;
} else {
yesterday = (today + yesterday) % b;
if (i == n - 1 && yesterday != 0) {
tGarbage ++;
}
}
garbage += tGarbage;
}
System.out.println(garbage);
}
}
#include <iostream>
using namespace std;
int main()
{
float a, b;
int t;
char o;
cout<<"Enter number of test cases: ";
cin>>t;
float ans[t];
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
if(t>0 && t<=100)
{
for(int i=0; i<t; i++)
{
cout<<"Enter number A: ";
cin>>a;
cout<<"Enter number B: ";
cin>>b;
cout<<"Enter operation: (+, -, *, /) : ";
cin>>o;
if(o == '+')
{
ans[i] = a + b;
}
else if(o == '-')
{
ans[i] = a - b;
}
else if(o == '*')
{
ans[i] = a * b;
}
else if(o == '/')
{
ans[i] = a / b;
}
else
cout<<"\nNaN";
}
for(int i=0; i<t; i++)
cout<<ans[i]<<endl;
}
return 0;
}
run-error
) (Time Submission : 13:53) (Problem :D - Smart Garbage Disposal System
)
import java.util.Scanner;
public class d {
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
String line = scan.nextLine();
String[] word = line.split("\\W+");
int day = Integer.parseInt(word[0]);
int capacity = Integer.parseInt(word[1]);
Scanner scan2 = new Scanner(System.in);
int total=0;
for(int i=0;i<day;i++){
int n = scan2.nextInt();
total=total+n;
}
int result = 0;
int count =0;
while(result<total){
result = capacity*count;
count++;
}
System.out.println(String.valueOf(count-1));
}
}
#include <iostream>
using namespace std;
void calc(float a, char o, float b)
{
if(o == '+')
{
printf("%.02f", a+b);
}
else if(o == '-')
{
printf("%.02f", a-b);
}
else if(o == '*')
{
printf("%.02f", a*b);
}
else if(o == '/')
{
if(b == 0)
cout << "NaN";
else
printf("%.02f", a/b);
}
cout << endl;
}
int main()
{
int t;
cin >> t;
while(t--)
{
char o;
float a, b;
cin >> a >> o >> b;
if(a < 0 || b > 10000)
cout << "NaN";
else
calc(a,o,b);
}
}
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 330;
int n, k, d;
vector<int> arr[350];
pair<pair<int, ll>, pii> pro[350];
int shit[100100];
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 350; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
vector<int> tmp;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC) arr[a][j] += h;
shit[arr[a][j] % k]++;
if (shit[arr[a][j] % k] == 1) ++uni;
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= r % MAGIC) arr[b][j] += h;
shit[arr[b][j] % k]++;
if (shit[arr[b][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC && j <= r % MAGIC) arr[a][j] += h;
shit[arr[a][j] % k]++;
if (shit[arr[a][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (j > 0) ans -= (pro[j].S.S % k == pro[j-1].S.F % k);
}
printf("%d\n", ans);
}
return 0;
}
//package prosolve_im26c4u;
import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.util.regex.Pattern;
public class Main {
// public static void main(String args[]) throws IOException {
// String input = "a.in";
// String output = "a.out";
// boolean file = false;
// BufferedReader br;
// if (file) {
// br = new BufferedReader(new FileReader(input));
// } else {
// br = new BufferedReader(new InputStreamReader(System.in));
// }
// PrintWriter pr;
// if (file) {
// pr = new PrintWriter(new FileWriter(output));
// } else {
// pr = new PrintWriter(System.out);
// }
//
// StringTokenizer st = new StringTokenizer(br.readLine());
// int n = Integer.parseInt(st.nextToken());
// int q = Integer.parseInt(st.nextToken());
// Pair p[] = new Pair[n];
// for (int i = 0; i < n; i++) {
// st = new StringTokenizer(br.readLine());
// int t = Integer.parseInt(st.nextToken());
// int x = Integer.parseInt(st.nextToken());
// p[i] = new Pair(t, x);
// }
// Arrays.sort(p);
// int min = p[0].t;
// int max = p[n - 1].t;
// for (int i = 0; i < q; i++) {
// int value = Integer.parseInt(br.readLine());
//
// if (value <= min) {
// System.out.println(-1 + " " + -1 + " " + min);
// } else if (value >= max) {
// System.out.println(p[n - 1].x + " " + max + " " + "-1");
// } else {
// int low = 0;
// int high = n - 1;
// int leftIndex = -1;
// while (low <= high) {
// int mid = (low + high) / 2;
// if (p[mid].t <= value) {
// low = mid + 1;
// if (leftIndex == -1) {
// leftIndex = mid;
// } else {
// leftIndex = Math.max(leftIndex, mid);
// }
// } else {
// high = mid - 1;
// }
// }
// System.out.println(p[leftIndex].x + " " + p[leftIndex].t + " " + p[leftIndex + 1].t);
// }
// }
// pr.close();
// }
//
// static class Pair implements Comparable<Pair> {
//
// int t = 0;
// int x = 0;
//
// Pair(int t, int x) {
// this.t = t;
// this.x = x;
// }
//
// @Override
// public int compareTo(Pair p) {
// return this.t - p.t;
// }
// }
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int count = st.countTokens();
int arr[] = new int[count];
for(int i=0;i<count;i++){
int v = Integer.parseInt(st.nextToken());
arr[i] = v;
}
Arrays.sort(arr);
Pair p[] = new Pair[(count*(count-1))/2];
int gg = 0;
for(int i=0;i<arr.length;i++){
for(int j=i+1;j<arr.length;j++){
p[gg] = new Pair(arr[i],arr[j]);
gg++;
}
}
Arrays.sort(p);
int diff = Integer.parseInt(br.readLine());
ArrayList<Pair> pairs = new ArrayList<>();
for(Pair pp:p){
if(pp.dist()==diff){
pairs.add(pp);
}
}
if(pairs.size()==0){
System.out.println("No Pair Found");
}else{
System.out.print("Pair Found:");
for(int i=0;i<pairs.size();i++){
if(i!=0){
System.out.print(",");
}
System.out.print(" "+pairs.get(i).toS());
}
System.out.println();
}
}
static class Pair implements Comparable<Pair>{
int a = 0;
int b = 0;
Pair(int a,int b){
this.a = a;
this.b = b;
}
@Override
public int compareTo(Pair p){
return (this.b-this.a)-(p.b-p.a);
}
public int dist(){
return this.b-this.a;
}
public String toS(){
return "("+a+", "+b+")";
}
}
}
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int prime(int input)
{
//prime
if(input == 1 || input== 2 ||input== 3 || input == 5 || ( input%2!=0 && input%3!=0 && input%5!=0))
return 0;
else
{
int hold[]={2,3,4,5,6,7,8,9};
for(int i=0;i <8;i++)
{
if(input%hold[i] == 0)
{
return hold[i];
}
}
}
}
int main(int argc, char** argv) {
int loop, input[20];
cin >> loop;
for(int i=0;i<loop;i++)
{
cin >> input[i];
}
for(int i = 0;i<loop;i++)
{
int out = prime(input[i]);
if (out == 0)
cout << "Prime\n";
else
cout << out << endl;
}
return 0;
}
#include <iostream>
using namespace std;
void calc(float a, char o, float b)
{
if(o == '+')
{
printf("%.02f", a+b);
}
else if(o == '-')
{
printf("%.02f", a-b);
}
else if(o == '*')
{
printf("%.02f", a*b);
}
else if(o == '/')
{
if(b == 0)
cout << "NaN";
else
printf("%.02f", a/b);
}
cout << endl;
}
int main()
{
int t;
cin >> t;
while(t--)
{
char o;
float a, b;
cin >> a >> o >> b;
if(a < 0 || b > 10000)
cout << "NaN" << endl;
else
calc(a,o,b);
}
}
import java.util.*;
import java.io.*;
import java.math.BigInteger;
class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] in = br.readLine().split(" ");
int n = Integer.parseInt(in[0]);
long b = Long.parseLong(in[1]);
String[] line = br.readLine().split(" ");
long garbage = 0, yesterday = 0;
for (int i = 0; i < n; i++) {
long today = Long.parseLong(line[i]);
long tGarbage = (today + yesterday) / b;
if (tGarbage == 0 && yesterday > 0) {
yesterday = 0;
tGarbage++;
} else {
yesterday = (today + yesterday) % b;
if (i == n - 1 && yesterday != 0) {
tGarbage ++;
}
}
garbage += tGarbage;
}
System.out.println(garbage);
}
}
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] inputs = br.readLine().split(" ");
int[] nums = new int[inputs.length];
for (int i = 0; i < nums.length; i++) {
nums[i] = Integer.parseInt(inputs[i]);
}
for (int i = 1; i < nums.length; i++) {
List<Integer> temp = new ArrayList<>();
StringBuilder sb = new StringBuilder("");
for (int j = 0; j < nums.length - i; j++) {
int diff = Math.abs(nums[j + 1] - nums[j]);
temp.add(diff);
sb.append(diff).append(" ");
}
System.out.println(sb.toString());
for (int j = 0; j < temp.size(); j++) {
nums[j] = temp.get(j);
}
}
}
}
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 320;
int n, k, d;
vector<int> arr[325];
pair<pair<int, ll>, pii> pro[325];
int shit[100100];
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 325; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
vector<int> tmp;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC) arr[a][j] += h;
shit[arr[a][j] % k]++;
if (shit[arr[a][j] % k] == 1) ++uni;
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= r % MAGIC) arr[b][j] += h;
shit[arr[b][j] % k]++;
if (shit[arr[b][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC && j <= r % MAGIC) arr[a][j] += h;
shit[arr[a][j] % k]++;
if (shit[arr[a][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (j > 0) ans -= (pro[j].S.S % k == pro[j-1].S.F % k);
}
printf("%d\n", ans);
}
return 0;
}
#include<iostream>
using namespace std;
int main(){
int notr, trlm, day;
cin >> notr >> trlm >> day;
int tr1, tr2, grow, pokok[notr]={0};
for(int i=0; i<day; i++){
cin >> tr1 >> tr2 >> grow;
for(int j=tr1-1;j<tr2;j++){
pokok[j] += grow;
if(pokok[j] >= trlm){
pokok[j] -= trlm;
}
}
int tent=1;
for(int j=0;j<notr-1;j++){
if(pokok[j] != pokok[j+1]){
tent++;
}
}
cout << tent << endl;
}
}
import java.util.Scanner;
public class A
{
public static void main(String []args){
Scanner input = new Scanner(System.in);
int flag = 0;
String lines = input.nextLine();
int s = input.nextInt();
String arr[] = lines.split(" ");
int count=0;
String newArr[]=new String[arr.length];
for(int x=0; x<arr.length-1; x++){
int com = Integer.parseInt(arr[x+1])-Integer.parseInt(arr[x]);
if(com==s){
newArr[count]= (Integer.parseInt(arr[x])+", "+Integer.parseInt(arr[x+1]));
count++;
}
}
for(int z=0; z<count-1; z++){
for(int x=0; x<count-1; x++){
String ns[] = newArr[x].split(", ");
String ns2[] = newArr[x+1].split(", ");
int aa = Integer.parseInt(ns[0]);
int bb = Integer.parseInt(ns2[0]);
if(aa>bb){
String temp=newArr[x];
newArr[x]=newArr[x+1];
newArr[x+1]=temp;
}
}
}
if(count>0)
for(int x=0; x<arr.length-1; x++){
int com = Integer.parseInt(arr[x+1])-Integer.parseInt(arr[x]);
if(com==s){
if(flag>0)
System.out.print(", ");
flag++;
if(flag==1)
System.out.print("Pair Found:" );
//String newLines = ("("+Integer.parseInt(arr[x])+", "+Integer.parseInt(arr[x+1])+")");
System.out.print("("+newArr[flag-1]+")");
}
}
else if(count==0)
System.out.println("No Pair Found");
}
}
from math import ceil
temp = input()
y = temp.split(" ")
y[0] = int(y[0])
y[1] = int(y[1])
total = 0
g = input().split(" ")
for countt in range(y[0]):
g[countt] = int(g[countt])
total = total + g[countt]
total = total / y[1]
print(ceil(total))
#include<bits/stdc++.h>
using namespace std;
int main()
{
int T;
double operation,A,B;
char O;
cin>>T;
for(int i=1;i<=T;++i)
{
if (T>=1 && T<=100)
{
cin>>A>>O>>B;
if((A>=1&&A<=10000)&&(B>=1&&B<=10000))
{
if(O=='+')
{
operation=A+B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else if (O=='-')
{
operation=A-B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else if(O=='*')
{
operation=A*B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else if(O=='/')
{
operation=A/B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else
{
cout<<"NaN"<<endl;
}
}
else
{
cout<<"NaN"<<endl;
}
}
}
return 0;
}
n,b=map(int,input().split())
a=list(map(int,input().split()))
carry=0
bag=0
for i in a:
bag+=-(-carry//b)
remain = carry%b
i-=remain
carry=i
print(bag)
import math
tc = input()
l,h,d = tc.split()
l = int(l)
h= int(h)
d = int(d)
def removeSame(z):
dik = dict()
for x in z:
dik[x] = 0
return len(dik)
day = []
for i in range(l):
day.append(0)
for i in range(d):
temp = input()
f, t, p = temp.split()
f = int(f)
f = f -1
t = int(t)
p = int(p)
for x in range(f,t,1):
tent = 1
day[x] += p
if day[x] >= h :
tent = (day[x] / h)
tent = math.floor(tent)+ 1
day[x] = abs(day[x] - (h* (tent-1)))
tent = removeSame(day)
print(tent)
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 320;
int n, k, d;
vector<int> arr[325];
pair<pair<int, ll>, pii> pro[325];
//int shit[100100];
hash_map<int, int> mp;
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 325; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
vector<int> tmp;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
mp.clear();
// memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC) arr[a][j] += h;
mp[arr[a][j] % k]++;
if (mp[arr[a][j] % k] == 1) ++uni;
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= r % MAGIC) arr[b][j] += h;
mp[arr[b][j] % k]++;
if (mp[arr[b][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC && j <= r % MAGIC) arr[a][j] += h;
mp[arr[a][j] % k]++;
if (mp[arr[a][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (j > 0) ans -= (pro[j].S.S % k == pro[j-1].S.F % k);
}
printf("%d\n", ans);
}
return 0;
}
#include <iostream>
#include<iomanip>
#include<cmath>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char** argv)
{
float A,B;
char O;
float sum,subtract,multiply,divide;
cin>>A>>O>>B;
switch(O)
{
case'+':
sum=(A+B);
cout<<fixed<<setprecision(2);
cout<<sum;
break;
case'-':
subtract=(A-B);
cout<<fixed<<setprecision(2);
cout<<subtract;
break;
case'*':
multiply=(A*B);
cout<<fixed<<setprecision(2);
cout<<multiply;
break;
case'/':
divide=(A/B);
cout<<fixed<<setprecision(2);
cout<<divide;
break;
default:
cout<<"NaN";
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ll n,b;cin>>n>>b;
ll ans=0,l=0;
for(int i=0;i<n;i++){
ll tm;cin>>tm;
ans+=ceil(l*1.0/b);
if(l%b!=0)
tm-=b-l%b;
l=0;
// cout<<ans<<" "<<tm<<endl;
if(tm>0){
ans+=tm/b;
l=tm%b;
}
// cout<<ans<<" - - "<<l<<endl;
}
if(l!=0)
ans+=ceil(l*1.0/b);
cout<<ans<<endl;
}
#include<iostream>
using namespace std;
int main()
{
int day;
int capacity;
int a;
double total = 0;
double bahagi = 0;
cout<<"day : ";
cin>>day;
cout<<"Garbage capacity : ";
cin>> capacity;
for (int i = 0; i<day;i++)
{
a = 0;
while(day!=0)
{
cout<<i+1<<"day :";
cin>>a;
total=total+a;
day--;
}
bahagi = total/capacity;
}
if(bahagi>1000000000)
{
cout<<"Total :"<<bahagi/1000000000<<"000000000"<<endl;
}
else
{
cout<<"Total :"<<bahagi<<endl;
}
}
#include<iostream>
using namespace std;
int main(){
int a[10];
cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4]>>a[5]>>a[6]>>a[7]>>a[8]>>a[9];
for(int i = 9; 0<i ;i--)
{
for(int j=0;i>j;j++)
{
a[j]=a[j]-a[j+1];
if(a[j]<0)
{
a[j] = a[j]*(-1);
}
cout<<a[j]<<" ";
}
cout<<"\n";
}
return 0;
}
n,b=map(int,input().split())
a=list(map(int,input().split()))
carry=0
bag=0
for i in a:
bag+=-(-carry//b)
remain = carry%b
i-=remain
carry=i
bag+=-(-carry//b)
print(bag)
#include<iostream>
#include<sstream>
#include<vector>
using namespace std;
struct vec2
{
int x,y;
vec2(int a,int b)
{
x=a;
y=b;
}
};
int main()
{
int num[10];
string input;
int counter = 0;
getline(cin,input);
stringstream ss(input);
while(ss>>num[counter]&&counter <10)
{
counter++;
}
if(counter<1||counter>9)
{
return 0;
}
int diff;
cin>>diff;
int a,b;
bool found =true;
bool first = true;
vector<vec2> pr;
for(int i=0;i<counter;i++)
{
for(int j=0;j<counter;j++)
{
if(i==j)continue;
a=num[i];
b=num[j];
if(a-b==diff&&b<=a){
pr.push_back(vec2(a,b));
if(found)
found = false;
}
}
}
if(found)
{
cout<<"No Pair Found";
}
else
{
for(int i=0;i<pr.size()-1;i++)
{
if(pr[i].x>pr[i+1].x)
{
vec2 temp = pr[i];
pr[i]=pr[i+1];
pr[i+1]=temp;
}
}
cout<<"Pair Found: ";
for(int i=0;i<pr.size();i++)
{
if(!first)cout<<", ";
cout<<"("<<pr[i].y<<", "<<pr[i].x<<")";
first=false;
}
}
return 0;
}
import java.util.Scanner;
public class F {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
for (int i = 0; i < n; i++) {
//String k = String.format("%14.2f");
double A = input.nextDouble();
double B = input.nextDouble();
if( A + B %2==0 ) {
double calc = A + B;
System.out.println( calc+"0");
}
else if( A - B %2==0 ) {
double calc2 = A - B;
System.out.println(calc2+"0");
}
else if( A * B %2==0 ) {
double calc3 = A * B;
System.out.println( calc3+"0");
}
else if( A / B %2==0 ) {
double calc4 = A / B;
System.out.println(calc4+"0");
}
else
System.out.println();
}
}
}
#include<iostream>
#include<sstream>
#include<vector>
using namespace std;
struct vec2
{
int x,y;
vec2(int a,int b)
{
x=a;
y=b;
}
};
int main()
{
int num[10];
string input;
int counter = 0;
getline(cin,input);
stringstream ss(input);
while(ss>>num[counter]&&counter <10)
{
counter++;
}
if(counter<1||counter>9)
{
return 0;
}
int diff;
cin>>diff;
int a,b;
bool found =true;
bool first = true;
vector<vec2> pr;
for(int i=0;i<counter;i++)
{
for(int j=0;j<counter;j++)
{
if(i==j)continue;
a=num[i];
b=num[j];
if(a-b==diff&&b<=a){
pr.push_back(vec2(a,b));
if(found)
found = false;
}
}
}
if(found)
{
cout<<"No Pair Found";
}
else
{
for(unsigned int i=0;i<pr.size()-1;i++)
{
if(pr[i].x>pr[i+1].x)
{
vec2 temp = pr[i];
pr[i]=pr[i+1];
pr[i+1]=temp;
}
}
cout<<"Pair Found: ";
for(unsigned int i=0;i<pr.size();i++)
{
if(!first)cout<<", ";
cout<<"("<<pr[i].y<<", "<<pr[i].x<<")";
first=false;
}
}
return 0;
}
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main()
{
int day;
int capacity;
int a;
double total = 0;
double bahagi = 0;
cout<<"day : ";
cin>>day;
cout<<"Garbage capacity : ";
cin>> capacity;
for (int i = 0; i<day;i++)
{
a = 0;
while(day!=0)
{
cout<<i+1<<"day :";
cin>>a;
total=total+a;
day--;
}
bahagi = total/capacity;
}
if(bahagi>1000000000)
{
cout<<"Total :"<<bahagi/1000000000<<"000000000"<<endl;
}
else
{
cout<<"Total :"<<round(bahagi)<<endl;
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
public class J {
public static void main(String args[]) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
StringBuffer sb = new StringBuffer();
int n= Integer.parseInt(st.nextToken());
int height = Integer.parseInt(st.nextToken());
int days= Integer.parseInt(st.nextToken());
int[] trees = new int[n];
for (int i=0;i<days;i++){
st = new StringTokenizer(br.readLine());
int initial= Integer.parseInt(st.nextToken());
int last = Integer.parseInt(st.nextToken());
int growth = Integer.parseInt(st.nextToken());
for (int j=initial-1;j<last;j++){
trees[j]+=growth;
if(trees[j]>=height){
trees[j]%=height;
}
}
sb.append(check(trees)).append("\n");
}
System.out.println(sb.toString());
}
public static int check(int[] array){
int tent=1;
for (int i=0;i<array.length-1;i++){
if(array[i]!=array[i+1]){
tent++;
}
}
return tent;
}
}
//package prosolve_im26c4u;
import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.util.regex.Pattern;
public class Main {
public static void main(String args[]) throws IOException {
String input = "a.in";
String output = "a.out";
boolean file = false;
BufferedReader br;
if (file) {
br = new BufferedReader(new FileReader(input));
} else {
br = new BufferedReader(new InputStreamReader(System.in));
}
PrintWriter pr;
if (file) {
pr = new PrintWriter(new FileWriter(output));
} else {
pr = new PrintWriter(System.out);
}
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int q = Integer.parseInt(st.nextToken());
Pair p[] = new Pair[n];
for (int i = 0; i < n; i++) {
st = new StringTokenizer(br.readLine());
int t = Integer.parseInt(st.nextToken());
int x = Integer.parseInt(st.nextToken());
p[i] = new Pair(t, x);
}
Arrays.sort(p);
int min = p[0].t;
int max = p[n - 1].t;
HashMap<Integer, String> queryReply = new HashMap<>();
for (int i = 0; i < q; i++) {
int value = Integer.parseInt(br.readLine());
// query here
if(queryReply.containsKey(value)){
// System.out.println("enter");
System.out.println(queryReply.get(value));
continue;
}
if (value <= min) {
String s = -1 + " " + -1 + " " + min;
System.out.println(s);
queryReply.put(value, s);
} else if (value >= max) {
String s = p[n - 1].x + " " + max + " " + "-1";
System.out.println(s);
queryReply.put(value, s);
} else {
int low = 0;
int high = n - 1;
int leftIndex = -1;
while (low <= high) {
int mid = (low + high) / 2;
if (p[mid].t <= value) {
low = mid + 1;
if (leftIndex == -1) {
leftIndex = mid;
} else {
leftIndex = Math.max(leftIndex, mid);
}
if(p[mid].t==value){
break;
}
} else {
high = mid - 1;
}
}
String s = p[leftIndex].x + " " + p[leftIndex].t + " " + p[leftIndex + 1].t;
System.out.println(s);
queryReply.put(value, s);
}
}
pr.close();
}
static class Pair implements Comparable<Pair> {
int t = 0;
int x = 0;
Pair(int t, int x) {
this.t = t;
this.x = x;
}
@Override
public int compareTo(Pair p) {
return this.t - p.t;
}
}
}
/**
* Write a description of class h here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.util.*;
import java.text.DecimalFormat;
public class h
{
public static void main (String args[])
{
Scanner inp = new Scanner(System.in);
DecimalFormat dec = new DecimalFormat("0.0000");
int i, N = inp.nextInt(); //N must be less than or equal to 100
double x[] = new double[N], y[] = new double[N], xa=0, ya=0, top=0, bot=0, beta, alpha;
for (i=0; i<N; i++)
{
x[i] = inp.nextDouble();
xa+=x[i];
y[i] = inp.nextDouble();
ya+=y[i];
}
xa/=N;
ya/=N;
int X = inp.nextInt();
double xnew[] = new double[X];
for (i=0; i<X; i++)
{
xnew[i] = inp.nextDouble();
}
for (i=0; i<N; i++)
{
top+=((x[i]-xa)*(y[i]-ya));
bot+=((x[i]-xa)*(x[i]-xa));
}
beta = top/bot;
alpha = ya-(beta*xa);
System.out.print(dec.format(beta));
System.out.print(" ");
System.out.println(dec.format(alpha)); //alpha
for (i=0; i<X; i++)
{
System.out.println(dec.format(alpha+beta*xnew[i])); //xnew
}
}
}
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char** argv) {
int loop, input[20];
int o = 1;
int hold[]={2,3,4,5,6,7,8,9};
cin >> loop;
for(int i=0;i<loop;i++)
{
cin >> input[i];
}
for(int i = 0;i<loop;i++)
{
o=1;
//prime
if(input[i] == 1 || input[i]== 2 ||input[i]== 3 || input[i] == 5 || ( input[i]%2!=0 && input[i]%3!=0 && input[i]%5!=0))
cout << "Prime\n";
else
{
for(int j=0;j <8;j++)
{
if(input[i]%hold[j] == 0)
{
if(o==1)
{
cout << hold[j] << endl;
o++;
}
}
}
}
}
return 0;
}
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int test;
float first, second;
char operators;
cout<<"Enter number of test cases : ";
cin>>test;
int j = 0;
int k = test;
float result[test];
if(test > 0 || test <=100)
{
while(test != 0)
{
cout<<"\n\nEnter expression : (NUMBER OPERAND NUMBER) "<<endl;
cin>>first>>operators>>second;
if((first>= 0.0 || first <=10000.0) && (second >=0.0 || second<=10000.0))
{ switch(operators)
{
case '+' : result[j] = first + second;
break;
case '-' : result[j] = first - second;
break;
case '*' : result[j] = first * second;
break;
case '/' : if(second != 0.0)
result[j] = first/second;
else
cout<<"NaN";
break;
default : cout<<operators<<"is unrecognised operation"<<endl;
return 0;
}
j++;
test--;
}
}
for(int j=0; j<k; j++)
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<"\n"<<result[j];
}
}
return 0;
}
import java.util.Scanner;
public class A
{
public static void main(String []args){
Scanner input = new Scanner(System.in);
int flag = 0;
String lines = input.nextLine();
int s = input.nextInt();
String arr[] = lines.split(" ");
int count=0;
String newArr[]=new String[arr.length];
for(int x=0; x<arr.length-1; x++){
int com = Integer.parseInt(arr[x+1])-Integer.parseInt(arr[x]);
com = Math.abs(com);
if(com==s){
newArr[count]= (Integer.parseInt(arr[x])+", "+Integer.parseInt(arr[x+1]));
count++;
}
}
for(int z=0; z<count-1; z++){
for(int x=0; x<count-1; x++){
String ns[] = newArr[x].split(", ");
String ns2[] = newArr[x+1].split(", ");
int aa = Integer.parseInt(ns[0]);
int bb = Integer.parseInt(ns2[0]);
if(aa>bb){
String temp=newArr[x];
newArr[x]=newArr[x+1];
newArr[x+1]=temp;
}
}
}
if(count>0)
for(int x=0; x<arr.length-1; x++){
int com = Integer.parseInt(arr[x+1])-Integer.parseInt(arr[x]);
com = Math.abs(com);
if(com==s){
if(flag>0)
System.out.print(", ");
++flag;
if(flag==1)
System.out.print("Pair Found:" );
//String newLines = ("("+Integer.parseInt(arr[x])+", "+Integer.parseInt(arr[x+1])+")");
System.out.print("("+newArr[flag-1]+")");
}
}
else if(count==0)
System.out.println("No Pair Found");
}
}
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 500;
int n, k, d;
vector<int> arr[325];
pair<pair<int, ll>, pii> pro[325];
//int shit[100100];
hash_map<int, int> mp;
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 325; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
vector<int> tmp;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
mp.clear();
// memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC) arr[a][j] += h;
mp[arr[a][j] % k]++;
if (mp[arr[a][j] % k] == 1) ++uni;
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= r % MAGIC) arr[b][j] += h;
mp[arr[b][j] % k]++;
if (mp[arr[b][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC && j <= r % MAGIC) arr[a][j] += h;
mp[arr[a][j] % k]++;
if (mp[arr[a][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (j > 0) ans -= (pro[j].S.S % k == pro[j-1].S.F % k);
}
printf("%d\n", ans);
}
return 0;
}
#include <iostream>
using namespace std;
int main()
{
float a, b;
int t;
char o;
cout<<"Enter number of test cases: ";
cin>>t;
float ans[t];
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
if(t>0 && t<=100)
{
for(int i=0; i<t; i++)
{
cout<<"Enter number A: ";
cin>>a;
cout<<"Enter number B: ";
cin>>b;
cout<<"Enter operation: (+, -, *, /) : ";
cin>>o;
if(o == '+')
{
ans[i] = a + b;
}
else if(o == '-')
{
ans[i] = a - b;
}
else if(o == '*')
{
ans[i] = a * b;
}
else if(o == '/')
{
ans[i] = a / b;
}
else
cout<<"\nNaN";
}
for(int i=0; i<t; i++)
cout<<ans[i];
}
return 0;
}
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 400;
int n, k, d;
vector<int> arr[325];
pair<pair<int, ll>, pii> pro[325];
//int shit[100100];
hash_map<int, int> mp;
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 325; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
vector<int> tmp;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
mp.clear();
// memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC) arr[a][j] += h;
mp[arr[a][j] % k]++;
if (mp[arr[a][j] % k] == 1) ++uni;
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= r % MAGIC) arr[b][j] += h;
mp[arr[b][j] % k]++;
if (mp[arr[b][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC && j <= r % MAGIC) arr[a][j] += h;
mp[arr[a][j] % k]++;
if (mp[arr[a][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (j > 0) ans -= (pro[j].S.S % k == pro[j-1].S.F % k);
}
printf("%d\n", ans);
}
return 0;
}
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
//int test;
//cin>>test;
//for(int i=0;i<test;i++)
//{
float a,b;
char sign;
cin>>a>>sign>>b;
if(sign=='+')
cout<<fixed<<setprecision(2)<<a+b<<endl;
else if(sign=='-')
cout<<fixed<<setprecision(2)<<a-b<<endl;
else if(sign=='*')
cout<<fixed<<setprecision(2)<<a*b<<endl;
else if(sign=='/')
{
if(b==0)
cout<<"NaN"<<endl;
else
cout<<fixed<<setprecision(2)<<a/b<<endl;
}
else
cout<<"NaN"<<endl;
// }
return 0;
}
t=int(input())
fib = [0 for _ in range(1000+1)]
fib[1]=2
fib[2]=3
for i in range(3,1001):
fib[i]=fib[i-1]+fib[i-2]
for _ in range(t):
n=int(input())
print(fib[n])
print("input no of sample")
sampleNo = int(input())
for i in range(sampleNo):
finding = input()
calculating = finding.split()
if calculating[1] == "+":
ans = int(calculating[0]) + int(calculating[2])
print ('%.2f'%ans)
elif calculating[1] == "-":
ans = int(calculating[0]) - int(calculating[2])
print ('%.2f'%ans)
elif calculating[1] == "*":
ans = int(calculating[0]) * int(calculating[2])
print ('%.2f'%ans)
elif calculating[1] == "/":
ans = int(calculating[0]) / int(calculating[2])
print ('%.2f'%ans)
#include<iostream>
using namespace std;
int main(){
int in=0;
cin>>in;
int c;
for(int r=0;r<in;r++){
c=0;
cin>>c;
if(c>2 && c%2==0)
cout<<2;
else if(c>3 && c%3==0)
cout<<3;
else if(c>5 && c%5==0)
cout<<5;
else if(c>7 && c%7==0)
cout<<7;
else if(c>9 && c%9==0)
cout<<9;
else
cout<<"Prime\n";
}
return 0;
}
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int test;
float first, second;
char operators;
cout<<"Enter number of test cases : ";
cin>>test;
int j = 0;
int k = test;
float result[test];
if(test > 0 || test <=100)
{
while(test != 0)
{
cout<<"\n\nEnter expression : (NUMBER OPERAND NUMBER) "<<endl;
cin>>first>>operators>>second;
if((first>= 0.0 || first <=10000.0) && (second >=0.0 || second<=10000.0))
{
switch(operators)
{
case '+' : result[j] = first + second;
break;
case '-' : result[j] = first - second;
break;
case '*' : result[j] = first * second;
break;
case '/' : if(second != 0.0)
result[j] = first/second;
break;
default : cout<<"NaN"<<endl;
return 0;
}
j++;
test--;
}
}
for(int j=0; j<k; j++)
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<"\n"<<result[j];
}
}
return 0;
}
def fun(n):
if(n == 2):
return 1
else:
return 2*fun(n-1)+(n-2)
tc = int(input())
for _ in range(tc):
num = int(input())
if(num == 1):
print("2")
else:
numz = fun(num)
print(2**num - numz)
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 600;
int n, k, d;
vector<int> arr[325];
pair<pair<int, ll>, pii> pro[325];
//int shit[100100];
hash_map<int, int> mp;
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 325; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
vector<int> tmp;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
mp.clear();
// memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC) arr[a][j] += h;
mp[arr[a][j] % k]++;
if (mp[arr[a][j] % k] == 1) ++uni;
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= r % MAGIC) arr[b][j] += h;
mp[arr[b][j] % k]++;
if (mp[arr[b][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC && j <= r % MAGIC) arr[a][j] += h;
mp[arr[a][j] % k]++;
if (mp[arr[a][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (j > 0) ans -= (pro[j].S.S % k == pro[j-1].S.F % k);
}
printf("%d\n", ans);
}
return 0;
}
import java.text.DecimalFormat;
import java.util.*;
import java.math.*;
public class h
{
public static void main (String [] args)
{
DecimalFormat df=new DecimalFormat("0.0000");
Scanner in=new Scanner(System.in);
ArrayList <Double> x= new ArrayList();
ArrayList <Double> y=new ArrayList();
double sx=0.0000, sy=0.0000, summul=0.0000, sumden=0.0000;
int cases=in.nextInt();
for (int i=0; i<cases;i++)
{
double a=in.nextDouble();
double b=in.nextDouble();
x.add(a);
y.add(b);
sx+=a;
sy+=b;
}
double ax=sx/cases;
double ay=sy/cases;
for (int i=0; i<cases;i++)
{
double mul=((x.get(i))-ax)*((y.get(i))-ay);
summul+=mul;
double den = Math.pow(x.get(i)-ax, 2);
sumden+=den;
}
double beta=summul/sumden;
double alpha=ay-(beta*ax);
System.out.println(df.format(beta) + " " + df.format(alpha));
int num=in.nextInt();
for (int i=0; i<num; i++)
{
double newx=in.nextDouble();
double res=alpha+(beta*newx);
System.out.println(df.format(res));
}
}
}
sampleNo = int(input())
for i in range(sampleNo):
finding = input()
calculating = finding.split()
if calculating[1] == "+":
ans = int(calculating[0]) + int(calculating[2])
print ('%.2f'%ans)
elif calculating[1] == "-":
ans = int(calculating[0]) - int(calculating[2])
print ('%.2f'%ans)
elif calculating[1] == "*":
ans = int(calculating[0]) * int(calculating[2])
print ('%.2f'%ans)
elif calculating[1] == "/":
ans = int(calculating[0]) / int(calculating[2])
print ('%.2f'%ans)
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int test;
cin>>test;
for(int i=0;i<test;i++)
{
float a,b;
char sign;
cin>>a>>sign>>b;
if(sign=='+')
cout<<fixed<<setprecision(2)<<a+b;
else if(sign=='-')
cout<<fixed<<setprecision(2)<<a-b;
else if(sign=='*')
cout<<fixed<<setprecision(2)<<a*b;
else if(sign=='/')
{
if(b==0)
cout<<"NaN";
else
cout<<fixed<<setprecision(2)<<a/b;
}
else
cout<<"NaN";
}
return 0;
}
#include <iostream>
using namespace std;
int main()
{
float a, b;
int t;
char o;
cin>>t;
float ans[t];
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
if(t>0 && t<=100)
{
for(int i=0; i<t; i++)
{
cin>>a>>o>>b;
if(o == '+')
{
ans[i] = a + b;
}
else if(o == '-')
{
ans[i] = a - b;
}
else if(o == '*')
{
ans[i] = a * b;
}
else if(o == '/')
{
ans[i] = a / b;
}
else
cout<<"\nNaN";
}
for(int i=0; i<t; i++)
cout<<ans[i];
}
return 0;
}
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main() {
int n1;
long long b;
cin>>n1>>b;
long long arr[n1];
for(int i=0;i<n1;i++){
cin>>arr[i];
}
long long extra = 0, num = 0;
for(int i = 0; i < n1 ; i+= 2) {
long long g = 0, n = 0;
if(i + 1 == n1){
g += (arr[i]) - extra;
}else{
g += (arr[i]) + (arr[i + 1]) - extra;
}
n = ceil((g*1.0)/(b*1.0));
num += n;
extra = (b * n - g);
}
cout << num;
return 0;
}
import java.io.*;
import java.text.*;
class Calculator{
public static void main (String [] args)throws IOException{
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
int T,i;
float A,B,AnsOfSum=0,AnsOfSub=0,AnsOfMulti=0,AnsOfDev=0;
char O;
Function obj = new Function();
String t1 = br.readLine();
T = Integer.parseInt(t1);
if( (T >=1) || (T<=100) ){
for (i=0;i<T;i++){
String InpA = br.readLine();
A = Float.parseFloat(InpA);
String InpO = br.readLine();
O = InpO.charAt(0);
String InpB = br.readLine();
B = Float.parseFloat(InpB);
if(O == '+'){
AnsOfSum = Function.sum(A,B);
System.out.print(AnsOfSum);
}else if(O == '-'){
AnsOfSub = Function.sub(A,B);
System.out.print(AnsOfSub);
}else if(O == '*'){
AnsOfMulti = Function.multi(A,B);
System.out.print(AnsOfMulti);
}else if(O == '/'){
AnsOfDev = Function.dev(A,B);
System.out.print(AnsOfDev);
}
}
}
}
}
class Function{
float c;
public float sum(float a,float b)
{
c=a+b;
return c;
}
public float sub(float a,float b)
{
c=a-b;
return c;
}
public float multi(float a,float b)
{
c=a*b;
return c;
}
public float dev(float a,float b)
{
c=a/b;
return c;
}
}
import java.math.BigInteger;
import java.util.*;
public class d {
public static void main (String [] args)
{
Scanner in=new Scanner(System.in);
BigInteger n= in.nextBigInteger();
BigInteger b=in.nextBigInteger();
BigInteger c=BigInteger.ZERO;
for (int i=0; i<n.intValue(); i++)
{
c=c.add(in.nextBigInteger());
}
if (c.remainder(b).intValue()!=0)
{
System.out.print((c.divide(b).add(BigInteger.ONE)));
}
else
{
System.out.print(c.divide(b));
}
}
}
#include<iostream>
#include<sstream>
#include <string>
#include<math.h>
using namespace std;
int main(){
string str;
//cin.ignore(100, '\n');
getline(cin, str);
//sstream ss;
string next=" ";
int count=0, pos=0, pre=0;
pos= str.find(next);
//int ar[T];
string w[10];
while(pos != -1){
w[count] = str.substr(pre, pos-pre);
count++;
if(str.find(next, pos +1) == -1){
pre = pos + 1;
w[count] = str.substr(pre, str.length());
count++;
}
pre = pos + 1;
pos = str.find(next, pos +1);
}
int nar[count];
for(int i = 0; i < count; i++)
{
stringstream ss;
ss << w[i];
ss >> nar[i];
}
while(count > 1)
{
for(int i = 0; i < count - 1; i++)
{
nar[i] -= nar[i + 1];
nar[i] = abs(nar[i]);
cout << nar[i] << " ";
}
count--;
cout << endl;
}
/*
for(int i=0;i<T;i++){
cin >> ar[i];
}
for(int i=0;i<T;i++){
}
size = T;
while(size != 1){
}*/
}
import java.util.Scanner;
public class Calculator {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
for (int i = 0; i < n; i++) {
//String k = String.format("%14.2f");
double A = input.nextDouble();
double B = input.nextDouble();
if( A + B %2==0 ) {
double calc = A + B;
System.out.println( calc+"0");
}
else if( A - B %2==0 ) {
double calc2 = A - B;
System.out.println(calc2+"0");
}
else if( A * B %2==0 ) {
double calc3 = A * B;
System.out.println( calc3+"0");
}
else if( A / B %2==0 ) {
double calc4 = A / B;
System.out.println(calc4+"0");
}
else
System.out.println();
}
}
}
#include<iostream>
#include<sstream>
#include<vector>
using namespace std;
struct vec2
{
int x,y;
vec2(int a,int b)
{
x=a;
y=b;
}
};
int main()
{
int num[10];
string input;
int counter = 0;
getline(cin,input);
stringstream ss(input);
while(ss>>num[counter]&&counter <10)
{
counter++;
}
if(counter<1||counter>9)
{
cout<<"array too short or too long";
return 0;
}
int diff;
cin>>diff;
int a,b;
bool found =true;
bool first = true;
vector<vec2> pr;
for(int i=0;i<counter;i++)
{
for(int j=0;j<counter;j++)
{
if(i==j)continue;
a=num[i];
b=num[j];
if(a-b==diff&&b<=a){
pr.push_back(vec2(a,b));
if(found)
found = false;
}
}
}
if(found)
{
cout<<"No Pair Found";
}
else
{
for(unsigned int i=0;i<pr.size()-1;i++)
{
if(pr[i].x>pr[i+1].x)
{
vec2 temp = pr[i];
pr[i]=pr[i+1];
pr[i+1]=temp;
}
}
cout<<"Pair Found: ";
for(unsigned int i=0;i<pr.size();i++)
{
if(!first)cout<<", ";
cout<<"("<<pr[i].y<<", "<<pr[i].x<<")";
first=false;
}
}
return 0;
}
from collections import defaultdict
n,q=map(int,input().split())
sensor=[]
sd = defaultdict(int)
for i in range(n):
a,b=map(int,input().split())
sensor.append([a,b])
sd[a]=i
sensor=sorted(sensor)
for _ in range(q):
reading=int(input())
if sd[reading]:
index=sd[reading]
else:
j=n//2
left=0
right=n-1
index=None
test=0
if reading<sensor[0][0]:
print(-1,-1,sensor[0][0])
continue
if reading>sensor[n-1][0]:
print(sensor[n-1][1],sensor[n-1][0],-1)
continue
while left<right-1:
if sensor[j][0]==reading:
index=j
break
elif sensor[j][0]<reading:
left=j+1
index=j+1
else:
right=j-1
index=j-1
j=(right-left+1)//2
print(sensor[index][1],sensor[index][0],sensor[index+1][0])
#include<iostream>
using namespace std;
int main()
{
int n, q;
cin >> n >> q;
long long int disp[n];
long long int count = 0, trash = 0;
for(int x = 0; x < n; x++)
{
cin >> disp[x];
trash += disp[x];
if(x != (n - 1))
{
if(trash < q && x > 0)
count++;
else
{
while(trash >= q)
{
trash -= q;
count ++;
}
}
}
else
{
while(trash > 0)
{
trash -= q;
count ++;
}
}
}
cout << count << endl;
}
import java. util.*;
public class a
{
public static void main (String[] args)
{
Scanner in=new Scanner(System.in);
ArrayList a=new ArrayList();
String b= in.nextLine();
int e=in.nextInt();
int count=0;
StringTokenizer c=new StringTokenizer(b, " ");
while (c.hasMoreTokens())
{
a.add(Integer.parseInt(c.nextToken()));
}
int[] d= new int[a.size()];
boolean found=false;
for (int i=0; i<a.size(); i++)
{
d[i]=Integer.parseInt(a.get(i).toString());
}
Arrays.sort(d);
for (int i=0; i<d.length-1; i++)
{
if (d[i+1]-d[i]==e)
{
found=true;
break;
}
}
for (int i = 0; i < d.length-1; i++) {
if (d[i + 1] - d[i] == e)
count++;
}
if(found)
{
System.out.print("Pair Found: " );
for (int i = 0; i < d.length-1; i++) {
if (d[i + 1] - d[i] == e) {
System.out.print("(" + d[i] + ", " + d[i + 1] + ")");
count--;
if(count>0)
{
System.out.print(", ");
}
}
}
found = true;
}
if (!found)
System.out.print("No Pair Found");
}
}
// Pair Found: (5, 10), (10, 15)
// Pair Found: (5, 10), (10, 15)
import java.io.*;
import java.text.*;
class Calculator{
public static void main (String [] args)throws IOException{
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
int T,i;
float A,B,AnsOfSum=0,AnsOfSub=0,AnsOfMulti=0,AnsOfDev=0;
char O;
String t1 = br.readLine();
T = Integer.parseInt(t1);
if( (T >=1) || (T<=100) ){
for (i=0;i<T;i++){
String InpA = br.readLine();
A = Float.parseFloat(InpA);
String InpO = br.readLine();
O = InpO.charAt(0);
String InpB = br.readLine();
B = Float.parseFloat(InpB);
if(O == '+'){
AnsOfSum = A+B;
System.out.print(AnsOfSum);
}else if(O == '-'){
AnsOfSub = A-B;
System.out.print(AnsOfSub);
}else if(O == '*'){
AnsOfMulti = A*B;
System.out.print(AnsOfMulti);
}else if(O == '/'){
AnsOfDev = A/B;
System.out.print(AnsOfDev);
}
}
}
}
}
#include<iostream>
#include<sstream>
#include<vector>
using namespace std;
struct vec2
{
int x,y;
vec2(int a,int b)
{
x=a;
y=b;
}
};
int main()
{
int num[10];
string input;
int counter = 0;
getline(cin,input);
stringstream ss(input);
while(ss>>num[counter]&&counter <10)
{
counter++;
}
// if(counter<1||counter>9)
// {
// cout<<"array too short or too long";
// return 0;
// }
int diff;
cin>>diff;
int a,b;
bool found =true;
bool first = true;
vector<vec2> pr;
for(int i=0;i<counter;i++)
{
for(int j=0;j<counter;j++)
{
if(i==j)continue;
a=num[i];
b=num[j];
if(a-b==diff&&b<=a){
pr.push_back(vec2(a,b));
if(found)
found = false;
}
}
}
if(found)
{
cout<<"No Pair Found";
}
else
{
for(unsigned int i=0;i<pr.size()-1;i++)
{
if(pr[i].x>pr[i+1].x)
{
vec2 temp = pr[i];
pr[i]=pr[i+1];
pr[i+1]=temp;
}
}
cout<<"Pair Found: ";
for(unsigned int i=0;i<pr.size();i++)
{
if(!first)cout<<", ";
cout<<"("<<pr[i].y<<", "<<pr[i].x<<")";
first=false;
}
}
return 0;
}
import java.util.*;
public class QA{
public static void main(String arg[])
{
Scanner input = new Scanner(System.in);
String num = input.nextLine();
int num3 = input.nextInt();
String line[] = num.split(" ");
int num2[]= new int[line.length];
for(int i=0; i<line.length; i++)
{
num2[i] = Integer.parseInt(line[i]);
}
boolean found=false;
boolean next=false;
int head=0;
for(int i=0; i<num2.length; i++)
{
for(int j=i; j<num2.length;j++)
{
found=true;
head++;
if(head==1)
{
System.out.print("Pair Found: ");
}
if(num2[i]<=num2[j] && (num2[j]-num2[i])==num3)
{
if (next==true)
{
System.out.print(", ");
}
System.out.print("("+num2[i]+","+num2[j]+")");
next=true;
}
else if(num2[i]>=num2[j] && (num2[i]-num2[j])==num3)
{
if (next==true)
{
System.out.print(", ");
}
System.out.print("("+num2[i]+","+num2[j]+")");
next=true;
}
}
}
if(found==false)
{
System.out.print("No Pair Found");
}
}
}
# import math
# reading = []
# import math
# def findlowerindex(inp, indexl, indexr):
# index = math.floor(indexl +((indexr - indexl)/2))
# if index==indexl:
# if reading[index][0]==inp:
# return index
# elif inp > reading[index][0]:
# return findlowerindex(inp,index, indexr )
# else:
# return findlowerindex(inp,indexl, index )
# while True:
if __name__ == '__main__':
# try:
line1 = input().split()
n = int(line1[0])
q = int(line1[1])
reading = []
for i in range(n):
inp = input().split()
reading.append((int(inp[0]), int(inp[1])))
reading.sort(key = lambda x : x[0])
# print(reading)
for i in range(q):
inp = int(input())
# print(findlowerindex(inp, 0, len(reading)))
for i in range(len(reading)):
if inp == reading[i][0]:
if i == len(reading) - 1:
print("%d %d %d" % (reading[i][1], reading[i][0], -1))
break
else:
if i + 1 >= len(reading):
print("%d %d %d" % (reading[i][1], reading[i][0], -1))
break
print("%d %d %d" % (reading[i][1], reading[i][0], reading[i + 1][0]))
break
if inp < reading[i][0]:
if i == 0:
print("%d %d %d" % (-1, -1, reading[i][0]))
break
print("%d %d %d" % (reading[i - 1][1], reading[i - 1][0], reading[i][0]))
break
if i == len(reading) - 1:
print("%d %d %d" % (reading[i][1], reading[i][0], -1))
# # if inp < reading[i][0]:
# # if i == 0:
# # print("%d %d %d" % (-1, -1, reading[i][0]))
# # break
# # else:
# # print("%d %d %d" % (reading[i - 1][1], reading[i - 1][0], reading[i][0]))
# # break
# # elif inp == reading[i][0]:
# # # if i == len(reading) - 1:
# # # print("%d %d %d" % (reading[i][1], reading[i][0], reading[i + 1][0]))
# # print("%d %d %d" % (reading[i][1], reading[i][0], reading[i + 1][0]))
# # break
# # else:
# # print("%d %d %d" % (reading[i][1], reading[i][0], -1))
# # break
# except Exception as e:
# print(e)
# break
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int n = 0;
cin >> n;
for(int t = 0; t < n; t++)
{
bool show = true;
float x, y, total;
char z;
cin >> x >> z >> y;
if(z == '+')
total = x + y;
else if(z == '-')
total = x - y;
else if(z == '*')
total = x * y;
else if(z == '/')
{
if(y != 0)
total = x / y;
else
show = false;
}
if(show == true)
{
cout << fixed << showpoint << setprecision(2);
cout << total << endl;
}
else
cout <<"NaN" << endl;
}
}
//package prosolve_im26c4u;
import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.util.regex.Pattern;
public class Main {
// public static void main(String args[]) throws IOException {
// String input = "a.in";
// String output = "a.out";
// boolean file = false;
// BufferedReader br;
// if (file) {
// br = new BufferedReader(new FileReader(input));
// } else {
// br = new BufferedReader(new InputStreamReader(System.in));
// }
// PrintWriter pr;
// if (file) {
// pr = new PrintWriter(new FileWriter(output));
// } else {
// pr = new PrintWriter(System.out);
// }
//
// StringTokenizer st = new StringTokenizer(br.readLine());
// int n = Integer.parseInt(st.nextToken());
// int q = Integer.parseInt(st.nextToken());
// Pair p[] = new Pair[n];
// for (int i = 0; i < n; i++) {
// st = new StringTokenizer(br.readLine());
// int t = Integer.parseInt(st.nextToken());
// int x = Integer.parseInt(st.nextToken());
// p[i] = new Pair(t, x);
// }
// Arrays.sort(p);
// int min = p[0].t;
// int max = p[n - 1].t;
//
// HashMap<Integer, String> queryReply = new HashMap<>();
//
// for (int i = 0; i < q; i++) {
// int value = Integer.parseInt(br.readLine());
//
// // query here
// if(queryReply.containsKey(value)){
//// System.out.println("enter");
// System.out.println(queryReply.get(value));
// continue;
// }
//
// if (value <= min) {
// String s = -1 + " " + -1 + " " + min;
// System.out.println(s);
// queryReply.put(value, s);
// } else if (value >= max) {
// String s = p[n - 1].x + " " + max + " " + "-1";
// System.out.println(s);
// queryReply.put(value, s);
// } else {
// int low = 0;
// int high = n - 1;
// int leftIndex = -1;
// while (low <= high) {
// int mid = (low + high) / 2;
// if (p[mid].t <= value) {
// low = mid + 1;
// if (leftIndex == -1) {
// leftIndex = mid;
// } else {
// leftIndex = Math.max(leftIndex, mid);
// }
// if(p[mid].t==value){
// break;
// }
// } else {
// high = mid - 1;
// }
// }
// String s = p[leftIndex].x + " " + p[leftIndex].t + " " + p[leftIndex + 1].t;
// System.out.println(s);
// queryReply.put(value, s);
// }
// }
// pr.close();
// }
//
// static class Pair implements Comparable<Pair> {
//
// int t = 0;
// int x = 0;
//
// Pair(int t, int x) {
// this.t = t;
// this.x = x;
// }
//
// @Override
// public int compareTo(Pair p) {
// return this.t - p.t;
// }
// }
public static void main(String args[]) throws IOException {
String input = "a.in";
String output = "a.out";
boolean file = false;
BufferedReader br;
if (file) {
br = new BufferedReader(new FileReader(input));
} else {
br = new BufferedReader(new InputStreamReader(System.in));
}
PrintWriter pr;
if (file) {
pr = new PrintWriter(new FileWriter(output));
} else {
pr = new PrintWriter(System.out);
}
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int q = Integer.parseInt(st.nextToken());
Pair p[] = new Pair[n];
for (int i = 0; i < n; i++) {
st = new StringTokenizer(br.readLine());
int t = Integer.parseInt(st.nextToken());
int x = Integer.parseInt(st.nextToken());
p[i] = new Pair(t, x);
}
Arrays.sort(p);
int query[] = new int[100001];
Arrays.fill(query,-1);
for(int i=0;i<p.length;i++){
query[p[i].t] = i;
}
int last = -1;
for(int i=0;i<=100000;i++){
if(query[i]==-1){
query[i] = last;
}else{
last = query[i];
}
}
for (int i = 0; i < q; i++) {
int value = Integer.parseInt(br.readLine());
if(query[value]==-1){
System.out.println("-1 -1 "+p[0].t);
}else{
System.out.print(p[query[value]].x+" "+p[query[value]].t);
if(query[value]==n-1){
System.out.print(" "+"-1");
}else{
System.out.print(" "+p[query[value]+1].t);
}
System.out.println();
}
}
pr.close();
}
static class Pair implements Comparable<Pair> {
int t = 0;
int x = 0;
Pair(int t, int x) {
this.t = t;
this.x = x;
}
@Override
public int compareTo(Pair p) {
return this.t - p.t;
}
}
}
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <cstring>
#include <ctype.h>
#include <cctype>
#include <iomanip>
using namespace std;
int main(int argc, char** argv)
{
int n;
float x;
float y;
char operation;
cin >> n;
float arr[n];
for (int j = 0; j < n; j++)
{
cin >> x >> operation>> y;
if (operation == '+')
arr[j] = x + y;
else if (operation == '-')
arr[j] = x - y;
else if (operation == '*')
arr[j] = x * y;
else if (operation == '/')
arr[j] = x / y;
else
cout << "NaN";
}
for(int j=0;j<n;j++){
cout << setprecision(2) << fixed << arr[j] << endl;
}
return 0;
}
import java.util.Scanner;
public class I {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int x = input.nextInt();
int factor;
for (factor = 2; factor <= x / factor; factor++)
if (x % factor == 0) break;
if (factor > x / factor)
System.out.println("Prime");
else{
System.out.println(Math.sqrt(x));
}
}
}
#include<iostream>
#include<sstream>
#include <string>
#include<math.h>
using namespace std;
int main(){
string str;
//cin.ignore(100, '\n');
getline(cin, str);
//sstream ss;
string next=" ";
int count=0, pos=0, pre=0;
pos= str.find(next);
//int ar[T];
string w[10];
while(pos != -1){
w[count] = str.substr(pre, pos-pre);
count++;
if(str.find(next, pos +1) == -1){
pre = pos + 1;
w[count] = str.substr(pre, str.length());
count++;
}
pre = pos + 1;
pos = str.find(next, pos +1);
}
int nar[count];
for(int i = 0; i < count; i++)
{
stringstream ss;
ss << w[i];
ss >> nar[i];
}
int pa;
int c=0;
cin >> pa;
string pair = "Pair Found: ";
for(int i = 0; i < pa -1; i++)
{
if(nar[i] + pa == nar[i+1])
{
if(c>0)
{
pair += ", ";
}
c++;
stringstream ss;
ss << nar[i];
string pp;
ss >> pp;
stringstream sss;
sss << nar[i + 1];
string ppp;
sss >> ppp;
pair += "(" + pp + ", " + ppp + ")";
}
}
if(c > 0)
{
cout << pair;
}
else
{
cout << "No Pair Found";
}
/*
for(int i=0;i<T;i++){
cin >> ar[i];
}
for(int i=0;i<T;i++){
}
size = T;
while(size != 1){
}*/
}
import java.io.IOException;
import java.util.Scanner;
public class B {
public static void main(String[] args) throws IOException {
Scanner input = new Scanner(System.in);
int n =input.nextInt();
int q = input.nextInt();
int [] x = new int[n+2];
int [] y =new int[n+2];
for(int i =1;i<=n;i++){
x[0]=-1;
x[n+1]=-1;
y[0]=-1;
y[n+1]=-1;
x[i]=input.nextInt();
y[i]=input.nextInt();
}
for (int i=0;i<q;i++){
int reading =input.nextInt();
for(int j=0;j<=n;j++){
if(reading< x[j+1]||x[j+1]==-1){
System.out.println(y[j]+" "+x[j]+" "+x[j+1]);
break;
}
}
}
}
}
import java.io.*;
import java.text.*;
public class Calculator{
public static void main (String [] args)throws IOException{
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
int T,i;
float A,B,AnsOfSum=0,AnsOfSub=0,AnsOfMulti=0,AnsOfDev=0;
char O;
String t1 = br.readLine();
T = Integer.parseInt(t1);
if( (T >=1) || (T<=100) ){
for (i=0;i<T;i++){
String InpA = br.readLine();
A = Float.parseFloat(InpA);
String InpO = br.readLine();
O = InpO.charAt(0);
String InpB = br.readLine();
B = Float.parseFloat(InpB);
if(O == '+'){
AnsOfSum = A+B;
System.out.print(AnsOfSum);
}else if(O == '-'){
AnsOfSub = A-B;
System.out.print(AnsOfSub);
}else if(O == '*'){
AnsOfMulti = A*B;
System.out.print(AnsOfMulti);
}else if(O == '/'){
AnsOfDev = A/B;
System.out.print(AnsOfDev);
}
}
}
}
}
n,b=map(int,input().split())
a=list(map(int,input().split()))
carry=0
bag=0
for i in a:
bag+=-(-carry//b)
remain = carry%b
if remain>=i:
carry=0
else:
i-=remain
carry=i
bag+=-(-carry//b)
print(bag)
def fun(n):
n1 = 0
n2 = 1
n3 = 0
for _ in range(n+1):
n3 = n2 + n1
n1 = n2
n2 = n3
return n3
tc = int(input())
for _ in range(tc):
num = int(input())
print(fun(num))
import java.util.*;
class c{
public static void main(String []args){
Scanner sc = new Scanner(System.in);
int line = Integer.parseInt(sc.nextLine());
Integer[] n = new Integer[line];
for(int i = 0; i<n.length;i++){
n[i] = Integer.parseInt(sc.nextLine());
}
System.out.print("\n");
for(int i = 0; i<n.length ;i++){
print(n[i]);
}
System.out.print("\n");
}
public static void print(int n) {
int r = (int) Math.pow(2,n);
String output ="";
int count =0;
for (int i=0; i<r; i++) {
for (int j=n-1; j>=0; j--) {
output +=(i/(int) Math.pow(2, j))%2;
}
output += " ";
}
String []result = output.split(" ");
for(int i=0; i<result.length;i++){
if(!result[i].contains("00")) count++;
}
System.out.println(count);
}
}
num = input()
numsplit = num.split()
for cut in range(len(numsplit)):
numsplit[cut] = int(numsplit[cut])
count = 0
for cooot in range(len(numsplit)):
for count in range(len(numsplit)-1):
if numsplit[count+1] != None:
numsplit[count] = abs(numsplit[count] - numsplit[count + 1])
else:
numsplit[count] = None
numsplit[len(numsplit)-1] = None
for cit in range(len(numsplit)):
if numsplit[cit] != None:
print(numsplit[cit], end=" ")
print("")
import java.math.BigInteger;
import java. util.*;
public class a
{
public static void main (String[] args)
{
Scanner in=new Scanner(System.in);
ArrayList <BigInteger> a=new ArrayList();
String b= in.nextLine();
BigInteger e=in.nextBigInteger();
int count=0;
StringTokenizer c=new StringTokenizer(b, " ");
while (c.hasMoreTokens())
{
a.add(BigInteger.valueOf(Long.parseLong(c.nextToken())));
}
BigInteger[] d= new BigInteger[a.size()];
boolean found=false;
for (int i=0; i<a.size(); i++)
{
d[i]=a.get(i);
}
Arrays.sort(d);
for (int i=0; i<d.length-1; i++)
{
if (d[i+1].subtract(d[i]).compareTo(e)==0)
{
found=true;
break;
}
}
for (int i = 0; i < d.length-1; i++) {
if (d[i + 1].subtract(d[i]).compareTo(e)==0)
count++;
}
if(found)
{
System.out.print("Pair Found: " );
for (int i = 0; i < d.length-1; i++) {
if (d[i + 1].subtract(d[i]).compareTo(e)==0) {
System.out.print("(" + d[i] + ", " + d[i + 1] + ")");
count--;
if(count>0)
{
System.out.print(", ");
}
}
}
found = true;
}
if (!found)
System.out.print("No Pair Found");
}
}
// Pair Found: (5, 10), (10, 15)
// Pair Found: (5, 10), (10, 15)
#include<bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sf(x) scanf("%d\n", &x)
#define pf(x) printf("%d\n", &x)
#define all(x) x.begin(), x.end
#define fill(a,x)memset(a,x,sizeof a)
#define size_a(a)sizeof(a) / sizeof(a[0])
#define dbg(x) cerr <<(#x) << "is" <<x<<'\n'
#define repi(i,a,n) for (int i = (int)a;i<(int)n;++i)
#define repll(i,a,n) for (int i = (ll)a;i<(ll)n;++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef vector<ii>vii;
typedef vector<int>vi;
// Global Variable Declaration
int fast_fibonacci(int n){
int i=1,h=1,j=0,k=0,t;
while(n>0){
if(n%2 == 1)
t=j*h,j=i*h+j*k+t,i=i*k+t;
t=h*h,h=2*k*h+t,k=k*k + t,n=n/2;
}
return j;
}
int T;
int main(){
cin>> T;
while(T--){
int x;
cin>>x;
cout<<fast_fibonacci(x+2)<<endl;
}
return 0;
}
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int test;
cin>>test;
for(int i=0;i<test;i++)
{
float a,b;
char sign;
cin>>a>>sign>>b;
if(a=='\0'||b=='\0')
{
cout<<"NaN";
return 0;
}
if(sign=='+')
cout<<fixed<<setprecision(2)<<a+b;
else if(sign=='-')
cout<<fixed<<setprecision(2)<<a-b;
else if(sign=='*')
cout<<fixed<<setprecision(2)<<a*b;
else if(sign=='/')
{
if(b==0)
cout<<"NaN";
else
cout<<fixed<<setprecision(2)<<a/b;
}
else
cout<<"NaN";
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
int T;
double operation,A,B;
char O;
cin>>T;
for(int i=1;i<=T;++i)
{
if (T>=1 && T<=100)
{
cin>>A>>O>>B;
if((A>=1&&A<=10000)&&(B>=1&&B<=10000))
{
if(O=='+')
{
operation=A+B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else if (O=='-')
{
operation=A-B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else if(O=='*')
{
operation=A*B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else if(O=='/')
{
operation=A/B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else
{
cout<<"NaN"<<endl;
}
}
}
}
return 0;
}
/**
* Write a description of class f here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.util.*;
import java.math.*;
import java.text.DecimalFormat;
public class f
{
public static void main(String args[])
{
Scanner inp = new Scanner(System.in);
DecimalFormat dec = new DecimalFormat("0.00");
//System.out.println(" ");
int i, T = inp.nextInt();
for (i=0; i<T; i++)
{
int y=0;
String operation = inp.next();
int n = operation.length();
for (int j=0; j<n; j++)
{
if (operation.charAt(j) == ('+'))
{
y = j;
}
else if (operation.charAt(j) == ('-'))
{
y=j;
}
else if (operation.charAt(j) == ('*'))
{
y=j;
}
else if (operation.charAt(j) == ('/'))
{
y=j;
}
}
if (operation.charAt(y) == ('+'))
{
StringTokenizer c = new StringTokenizer(operation,"+");
double num1 = Double.parseDouble(c.nextToken());
double num2 = Double.parseDouble(c.nextToken());
System.out.println(dec.format(num1+num2));
}
else if (operation.charAt(y) == ('-'))
{
StringTokenizer c = new StringTokenizer(operation,"-");
double num1 = Double.parseDouble(c.nextToken());
double num2 = Double.parseDouble(c.nextToken());
System.out.println(dec.format(num1-num2));
}
else if (operation.charAt(y) == ('*'))
{
StringTokenizer c = new StringTokenizer(operation,"*");
double num1 = Double.parseDouble(c.nextToken());
double num2 = Double.parseDouble(c.nextToken());
System.out.println(dec.format(num1*num2));
}
else if (operation.charAt(y) == ('/'))
{
StringTokenizer c = new StringTokenizer(operation,"/");
double num1 = Double.parseDouble(c.nextToken());
double num2 = Double.parseDouble(c.nextToken());
if(num2 == 0)
System.out.println("NaN");
else
System.out.println(dec.format(num1/num2));
}
else if (y==0)
{
System.out.println("NaN");
}
}
}
}
���4O
!"# $%
&
'
(
)*
+,
-. $/
0123
0456<init>()VCodeLineNumberTablemain([Ljava/lang/String;)V
StackMapTable7"82
Exceptions9
SourceFileCalculator.javajava/io/BufferedReaderjava/io/InputStreamReader:;<=>?@ABCDEF8GHIJKLMjava/lang/ArithmeticExceptionnaNLN
Calculatorjava/lang/Object[Ljava/lang/String;java/lang/Stringjava/io/IOExceptionjava/lang/SysteminLjava/io/InputStream;(Ljava/io/InputStream;)V(Ljava/io/Reader;)VreadLine()Ljava/lang/String;java/lang/IntegerparseInt(Ljava/lang/String;)Ijava/lang/Float
parseFloat(Ljava/lang/String;)FcharAt(I)CoutLjava/io/PrintStream;java/io/PrintStreamprint(F)V(Ljava/lang/String;)V!*�� �ٻY�Y���L8888 +�:�=� d��>��+�:� 8+�:
�
6
+�:� 8
+�b8���K
-�f8���2
*�j8���
/�n8 � ��
:�����b�d��
v
$*5<BIOW]dkr }"�#�$�&�'�(�*�+�,�2�/�1��8y �5��EB� �
import java.util.*;
public class QA{
public static void main(String arg[])
{
Scanner input = new Scanner(System.in);
String num = input.nextLine();
int num3 = input.nextInt();
String line[] = num.split(" ");
int num2[]= new int[line.length];
for(int i=0; i<line.length; i++)
{
num2[i] = Integer.parseInt(line[i]);
}
boolean found=false;
boolean next=false;
int head=1;
for(int i=0; i<num2.length; i++)
{
for(int j=i; j<num2.length;j++)
{
if(num2[i]<=num2[j] && (num2[j]-num2[i])==num3)
{
found=true;
if(head==1)
{
System.out.print("Pair Found: ");
head++;
}
if (next==true)
{
System.out.print(", ");
}
System.out.print("("+num2[i]+","+num2[j]+")");
next=true;
}
else if(num2[i]>=num2[j] && (num2[i]-num2[j])==num3)
{
found=true;
if(head==1)
{
System.out.print("Pair Found: ");
head++;
}
if (next==true)
{
System.out.print(", ");
}
System.out.print("("+num2[i]+","+num2[j]+")");
next=true;
}
}
}
if(found==true)
{
System.out.println();
}
if(found==false)
{
System.out.println("No Pair Found");
}
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class D {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
long b = Long.parseLong(st.nextToken());
int num = 0;
st = new StringTokenizer(br.readLine());
long remain = 0;
for(int i =0;i<n;i++){
long next = Long.parseLong(st.nextToken());
num+=remain/b;
remain=remain%b;
if(next+remain>=b){
num+=(next+remain)/b;
remain = (next+remain)%b;
}
else{
if (i==n-1){
num++;
}else {
if (remain != 0) {
num++;
}
remain = next;
}
}
}
System.out.println(num);
}
}
import java.util.*;
class c{
public static void main(String []args){
Scanner sc = new Scanner(System.in);
int line = Integer.parseInt(sc.nextLine());
Integer[] n = new Integer[line];
for(int i = 0; i<n.length;i++){
n[i] = Integer.parseInt(sc.nextLine());
}
System.out.print("\n");
for(int i = 0; i<n.length ;i++){
int r = (int) Math.pow(2,n[i]);
String output ="";
int count =0;
for (int k=0; k<r; k++) {
for (int j=n[i]-1; j>=0; j--) {
output +=(k/(int) Math.pow(2, j))%2;
}
output += " ";
}
String []result = output.split(" ");
for(int j=0; j<result.length;j++){
if(!result[j].contains("00")) count++;
}
System.out.println(count);
}
System.out.print("\n");
}
}
while True:
try:
xys = int(input())
Xs = []
Ys = []
data = []
for i in range(xys):
line = input().split()
data.append((float(line[0]), float(line[1])))
Xs.append(float(line[0]))
Ys.append(float(line[1]))
x_sum = sum(Xs)
y_sum = sum(Ys)
x_mean = x_sum / len(Xs)
y_mean = y_sum / len(Ys)
summation_up = 0
summation_down = 0
for i in range(xys):
summation_up += (Xs[i] - x_mean) * (Ys[i] - y_mean)
summation_down += (Xs[i] - x_mean) ** 2
beta = summation_up/summation_down
alpha = y_mean - beta * x_mean
print('%.4f %.4f' % (beta, alpha))
q = int(input())
for i in range(q):
query = float(input())
print('%.4f' % (beta*query + alpha))
except Exception as e:
# print(e)
break
string = input()
num = string.split(' ')
st = list()
d = int(input())
l = len(num)
k=1
flag = False
for row in range(l-1):
for col in range(k,l):
s = int(num[row])
t = int(num[col])
ans = abs(s-t)
if ans == d:
ans = str(min(s,t)) + ',' + str(max(s,t))
st.append('('+ans+')')
flag = True
last = '('+ans+')'
k = k + 1
if flag:
print('Pair Found: ',end='')
for k in st:
if k == last:
print(k)
else:
print(k,end=', ')
else:
print('No Pair Found')
#include <iostream>
#include <cmath>
#include <cstdio>
#include <map>
using namespace std;
int main() {
int n,q;
cin >> n >> q;
int m[n][2];
for (int i=0;i<n;i++){
cin >> m[i][0] >> m[i][1];
}
for(int i=0;i<q;i++){
int index = 0,t,mid;
mid = n/2;
cin >> t;
if(m[0][0] > t){
index = -1;
}else if(m[mid][0]==t){
index = mid;
}else if(m[mid][0]>t){
for(int j=0; j<q;j++){
index = j;
if(m[j][0]>t){
index--;
break;
}
}
}else{
for(int j=mid; j<q;j++){
index = j;
if(m[j][0]>t){
index--;
break;
}
}
}
if(index == -1){
cout << -1 <<" "<<-1<<" "<<m[0][0]<<endl;
}else{
if(index == q-1){
index--;
}
cout << m[index][1]<<" "<<m[index][0]<<" ";
if(index +2 == q) cout<<-1<<endl;
else cout<< m[index+1][0]<<endl;
}
}
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int c,i,n;
bool isPrime = true;
cin>>c;
for(int t=1; t<=c; ++t)
{
cin>>n;
for(int i=2; i<=n/2; ++i)
{
if(n % i == 0)
{
isPrime = false;
}
}
if (isPrime)
{
cout << "Prime\n";
}
else
{
if (n%2 == 0)
{
cout<<"2\n";
}
else if (n%5 == 0)
{
cout<<"5\n";
}
}
}
return 0;
}
import java.util.Scanner;
public class A
{
public static void main(String []args){
Scanner input = new Scanner(System.in);
int flag = 0;
String lines = input.nextLine();
int s = input.nextInt();
String arr[] = lines.split(" ");
int count=0;
String newArr[]=new String[arr.length];
for(int x=0; x<arr.length-1; x++){
int com = Integer.parseInt(arr[x+1])-Integer.parseInt(arr[x]);
com = Math.abs(com);
if(com==s){
newArr[count]= (Integer.parseInt(arr[x])+", "+Integer.parseInt(arr[x+1]));
count++;
}
}
for(int z=0; z<count-1; z++){
for(int x=0; x<count-1; x++){
String ns[] = newArr[x].split(", ");
String ns2[] = newArr[x+1].split(", ");
int aa = Integer.parseInt(ns[0]);
int bb = Integer.parseInt(ns2[0]);
if(aa>bb){
String temp=newArr[x];
newArr[x]=newArr[x+1];
newArr[x+1]=temp;
}
}
}
if(count>0)
for(int x=0; x<arr.length-1; x++){
int com = Integer.parseInt(arr[x+1])-Integer.parseInt(arr[x]);
com = Math.abs(com);
if(com==s){
if(flag>0)
System.out.print(", ");
++flag;
if(flag==1)
System.out.print("Pair Found: " );
System.out.print("("+newArr[flag-1]+")");
}
}
else if(count==0)
System.out.println("No Pair Found");
}
}
#include<iostream>
using namespace std;
int main(){
int in=0;
cin>>in;
int c;
for(int r=0;r<in;r++){
c=0;
cin>>c;
if(c>2 && c%2==0)
cout<<2<<"\n";
else if(c>3 && c%3==0)
cout<<3<<"\n";
else if(c>5 && c%5==0)
cout<<5<<"\n";
else if(c>7 && c%7==0)
cout<<7<<"\n";
else if(c>9 && c%9==0)
cout<<9<<"\n";
else
cout<<"Prime\n";
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
int numPoints;
vector<float> x;
vector<float> y;
cin >> numPoints;
int a, b;
float xTotal = 0;
float yTotal = 0;
for(int i=0; i<numPoints; i++)
{
cin >> a >> b;
x.push_back(a);
y.push_back(b);
xTotal += a;
yTotal += b;
}
xTotal /= numPoints;
yTotal /= numPoints;
float up = 0;
float down = 0;
for(int i=0; i<numPoints; i++)
{
up += (x[i]-xTotal)*(y[i]-yTotal);
down += pow((x[i] - xTotal), 2);
}
float beta = up/down;
float alpha = yTotal - beta*xTotal;
int numPrediction;
cin >> numPrediction;
printf("%.04f %.04f\n", beta, alpha);
for(int i=0; i<numPrediction; i++)
{
int predict;
cin >> predict;
cout << (alpha + beta*predict) << endl;
}
}
#include <iostream>
using namespace std;
float add(char x)
{
}
int main()
{
float A,B,T;
char O;
cin>>T;
for(int i=0;i<T;i++)
{
cin>>A>>O>>B;
if(O == '+'){
float AnsOfSum = A+B;
cout<<AnsOfSum;
}else if(O == '-'){
float AnsOfSub = A-B;
cout<<AnsOfSub;
}else if(O == '*'){
float AnsOfMulti = A*B;
cout<<AnsOfMulti;
}else if(O == '/'){
float AnsOfDev = A/B;
cout<<AnsOfDev;
}
}
}
import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;
public class Narrow {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
String num = sc.nextLine();
String[] b = num.split(" ");
LinkedList<Integer> blist = new LinkedList<Integer>();
int ans = 0;
for (int i = 0; i < b.length; i++) {
blist.add(Integer.parseInt(b[i]));
}
while (!blist.isEmpty()) {
for (int k = 0; k < blist.size() - 1; k++) {
ans = blist.get(k) - blist.get(k + 1);
if (ans < 0) {
ans = ans * (-1);
}
System.out.print(ans + " ");
blist.set(k, ans);
}
blist.removeLast();
System.out.println();
}
}
}
#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;
int main()
{
int count;
cin >> count;
double x, y, total;
char symb;
for(int i = 0; i < count; i++)
{
cin >> x >> symb >> y;
if(symb == '+')
total = (x + y);
else if(symb == '-')
total = (x-y);
else if(symb == '*')
total = (x*y);
else if(symb == '/' && y==0)
total = NULL;
else if(symb == '/')
total = (x/y);
else
total = NULL;
if(total == NULL)
cout << "NaN" << endl;
else printf("%.2f\n", total);
}
}
#include <iostream>
using namespace std;
int main()
{
float A,B,T;
char O;
cin>>T;
for(int i=0;i<T;i++)
{
cin>>A>>O>>B;
if(O == '+'){
float AnsOfSum = A+B;
cout<<AnsOfSum;
}else if(O == '-'){
float AnsOfSub = A-B;
cout<<AnsOfSub;
}else if(O == '*'){
float AnsOfMulti = A*B;
cout<<AnsOfMulti;
}else if(O == '/'){
float AnsOfDev = A/B;
cout<<AnsOfDev;
}
}
}
n,b=map(int,input().split())
a=list(map(int,input().split()))
carry=0
bag=0
for i in a:
if carry==0:
carry=i
continue
bag+=-(-carry//b)
if carry>=b:
remain = carry%b
else:
remain = b-carry%b
#print(bag,carry,remain,i)
if remain>=i:
carry=0
else:
i-=remain
carry=i
bag+=-(-carry//b)
print(bag)
#include<iostream>
using namespace std;
int main()
{
int a,b;
do
{
cin>>a>>b;
}while(a<1||b<1||a>20000||b>10000000000);
int garbage= 0;
int day;
for(int i=0;i<a;i++)
{
do
{
cin>>day;
}while(day<1||day>10000000000);
garbage +=day;
}
if((double)garbage/b>(int)garbage/b)
{
cout<<garbage/b + 1;
}
else
cout<<garbage/b;
return 0;
}
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int d,cb,n,i,total;
cin >>d>>cb;
int times[d] ;
for(int i=0;i<d;i++){
cin >> times[i];
}
for(int j=0;j<d;j++){
total = total+times[j];
}
int result = 0;
int count = 1;
while(result<total){
result = cb*count;
if(result<total){
count++;
}
}
cout<<count;
}
#include <iostream>
using namespace std;
int main()
{
float A,B,T;
char O;
cin>>T;
for(int i=0;i<T;i++)
{
cin>>A>>O>>B;
if(O == '+'){
float AnsOfSum = A+B;
cout<<AnsOfSum<<".00";
}else if(O == '-'){
float AnsOfSub = A-B;
cout<<AnsOfSub<<".00";
}else if(O == '*'){
float AnsOfMulti = A*B;
cout<<AnsOfMulti<<".00";
}else if(O == '/'){
float AnsOfDev = A/B;
cout<<AnsOfDev<<".00";
}
}
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
int numPoints;
vector<float> x;
vector<float> y;
cin >> numPoints;
int a, b;
float xTotal = 0;
float yTotal = 0;
for(int i=0; i<numPoints; i++)
{
cin >> a >> b;
x.push_back(a);
y.push_back(b);
xTotal += a;
yTotal += b;
}
xTotal /= numPoints;
yTotal /= numPoints;
float up = 0;
float down = 0;
for(int i=0; i<numPoints; i++)
{
up += (x[i]-xTotal)*(y[i]-yTotal);
down += pow((x[i] - xTotal), 2);
}
float beta = up/down;
float alpha = yTotal - beta*xTotal;
int numPrediction;
cin >> numPrediction;
printf("%.04f %.04f\n", beta, alpha);
for(int i=0; i<numPrediction; i++)
{
int predict;
cin >> predict;
cout << (alpha + beta*predict) << endl;
}
}
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int d,cb,total=0;
cin >>d>>cb;
int times[d] ;
for(int i=0;i<d;i++){
cin >> times[i];
}
for(int j=0;j<d;j++){
total = total+times[j];
}
int result = 0;
int count = 1;
while(result<total){
result = cb*count;
if(result<total){
count++;
}
}
cout<<count;
}
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
int T, N, n;
float t=0;
cin >> T >> N;
for(int i=0;i<T;i++){
cin >> n;
t+= n;
}
printf("%.0f", (t/N));
}
#include<iostream>
using namespace std;
int main()
{
long long a,b;
cin>>a>>b;
long long garbage= 0;
long long day;
for(int i=0;i<a;i++)
{
cin>>day;
garbage +=day;
}
if((double)garbage/b>(long long )garbage/b)
{
cout<<garbage/b + 1;
}
else
cout<<garbage/b;
return 0;
}
import java.util.Scanner;
public class I {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int y = input.nextInt();
for (int j = 0; j < y; j++) {
kira();
}
}
public static void kira(){
Scanner input = new Scanner(System.in);
int x = input.nextInt();
int factor;
for (factor = 2; factor <= x / factor; factor++)
if (x % factor == 0) break;
if (factor > x / factor)
System.out.println("Prime");
else{
System.out.println(Math.min(x,factor));
}
}
}
#include<iostream>
using namespace std;
int main()
{
int a;
cin >> a;
for(int b = 0; b < a; b++)
{
int num;
cin >> num;
int total = 1 + num;
for(int r = 2; r < num; r++)
{
int ncr, ncr2, fr = 1, fn = 1, fr1 = 1, fn1 = 1, fnr = 1, fnr1 = 1;
for(int c = 1; c <= num; c++)
fn = fn * c;
for(int d = 1; d <= r; d++)
fr = fr * d;
int aa = num - r;
for(int e = 1; e <= aa; e++)
fnr = fnr * e;
for(int f = 1; f <= aa; f++)
fnr1 = fnr1 * f;
fr1 = fr / r;
fn1 = fn / num;
ncr = fn / (fnr * fr) ;
ncr2 = fn1 / (fnr1 * fr1) ;
total = total + ncr - ncr2;
}
cout << total << endl;
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.StringTokenizer;
public class B {
public static void main(String[] args) throws IOException {
// Scanner input = new Scanner(System.in);
//
// int n =input.nextInt();
// int q = input.nextInt();
//
// int [] x = new int[n+2];
// int [] y =new int[n+2];
//
// for(int i =1;i<=n;i++){
// x[0]=-1;
// x[n+1]=-1;
// y[0]=-1;
// y[n+1]=-1;
// x[i]=input.nextInt();
// y[i]=input.nextInt();
// }
//
//
// for (int i=0;i<q;i++){
// int reading =input.nextInt();
//
// for(int j=0;j<=n;j++){
// if(reading< x[j+1]||x[j+1]==-1){
// System.out.println(y[j]+" "+x[j]+" "+x[j+1]);
// break;
// }
//
// }
// }
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb = new StringBuffer();
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int q = Integer.parseInt(st.nextToken());
LinkedList<Integer> time = new LinkedList<>();
LinkedList<Integer> readings = new LinkedList<>();
for(int i =0;i<n;i++){
st = new StringTokenizer(br.readLine());
time.add(Integer.parseInt(st.nextToken()));
readings.add(Integer.parseInt(st.nextToken()));
}
for(int i=0;i<q;i++){
int query = Integer.parseInt(br.readLine());
if (time.contains(query)){
int idx = time.indexOf(query);
sb.append(String.format("%d %d %d\n", readings.get(idx), query, time.get(idx + 1)));
}
else{
int idx = Math.abs(Collections.binarySearch(time, query))-1;
int nexttime, lasttime, lastreading;
if(query<time.getFirst()){
nexttime=time.getFirst();
lastreading=-1;
lasttime=-1;
}
else if(idx>=readings.size()){
nexttime=-1;
lastreading = readings.get(idx-1);
lasttime = time.get(idx-1);
}
else{
nexttime = time.get(idx);
lastreading = readings.get(idx-1);
lasttime = time.get(idx-1);
}
sb.append(String.format("%d %d %d\n", lastreading, lasttime, nexttime));
}
}
System.out.println(sb.toString());
}
}
def read():
return map(int, input().strip().split(" "))
n, q = read()
r = []
for i in range(n):
t, x = read()
r.append((t,x))
# r = sorted(r, key=lambda k: k[0])
for i in range(q):
a = int(input())
if r[0][0] > a:
print(-1,-1,r[0][0])
elif r[-1][0] < a:
print(r[-1][1], r[-1][0], -1)
else:
# for j in range(n):
# if r[j+1][0] > a:
# print(r[j][1], r[j][0], r[j+1][0])
# break
v, w = 0, len(r)
while True:
m = (v + w) // 2
if a >= r[m][0]:
if a < r[m + 1][0]:
break
v = m + 1
else:
if a >= r[m - 1][0]:
m -= 1
break
w = m - 1
print(r[m][1], r[m][0], r[m + 1][0])
//package prosolve_im26c4u;
import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.util.regex.Pattern;
public class Main {
// public static void main(String args[]) throws IOException {
// String input = "a.in";
// String output = "a.out";
// boolean file = false;
// BufferedReader br;
// if (file) {
// br = new BufferedReader(new FileReader(input));
// } else {
// br = new BufferedReader(new InputStreamReader(System.in));
// }
// PrintWriter pr;
// if (file) {
// pr = new PrintWriter(new FileWriter(output));
// } else {
// pr = new PrintWriter(System.out);
// }
//
// StringTokenizer st = new StringTokenizer(br.readLine());
// int n = Integer.parseInt(st.nextToken());
// int q = Integer.parseInt(st.nextToken());
// Pair p[] = new Pair[n];
// for (int i = 0; i < n; i++) {
// st = new StringTokenizer(br.readLine());
// int t = Integer.parseInt(st.nextToken());
// int x = Integer.parseInt(st.nextToken());
// p[i] = new Pair(t, x);
// }
// Arrays.sort(p);
// int min = p[0].t;
// int max = p[n - 1].t;
//
// HashMap<Integer, String> queryReply = new HashMap<>();
//
// for (int i = 0; i < q; i++) {
// int value = Integer.parseInt(br.readLine());
//
// // query here
// if(queryReply.containsKey(value)){
//// System.out.println("enter");
// System.out.println(queryReply.get(value));
// continue;
// }
//
// if (value <= min) {
// String s = -1 + " " + -1 + " " + min;
// System.out.println(s);
// queryReply.put(value, s);
// } else if (value >= max) {
// String s = p[n - 1].x + " " + max + " " + "-1";
// System.out.println(s);
// queryReply.put(value, s);
// } else {
// int low = 0;
// int high = n - 1;
// int leftIndex = -1;
// while (low <= high) {
// int mid = (low + high) / 2;
// if (p[mid].t <= value) {
// low = mid + 1;
// if (leftIndex == -1) {
// leftIndex = mid;
// } else {
// leftIndex = Math.max(leftIndex, mid);
// }
// if(p[mid].t==value){
// break;
// }
// } else {
// high = mid - 1;
// }
// }
// String s = p[leftIndex].x + " " + p[leftIndex].t + " " + p[leftIndex + 1].t;
// System.out.println(s);
// queryReply.put(value, s);
// }
// }
// pr.close();
// }
//
// static class Pair implements Comparable<Pair> {
//
// int t = 0;
// int x = 0;
//
// Pair(int t, int x) {
// this.t = t;
// this.x = x;
// }
//
// @Override
// public int compareTo(Pair p) {
// return this.t - p.t;
// }
// }
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
char table[][] = new char[N][M];
boolean visited[][] = new boolean[N][M];
Pair parent[][] = new Pair[N][M];
for(int i=0;i<N;i++){
Arrays.fill(parent[i],new Pair(-1,-1,-1));
}
Pair start = null;
Pair end = null;
for(int i=0;i<N;i++){
String line = br.readLine();
for(int j=0;j<M;j++){
char c = line.charAt(j);
table[i][j] = c;
if(c=='D'){
start = new Pair(i,j,0);
}else if(c=='C'){
end = new Pair(i,j,0);
}else if(c=='#'){
visited[i][j] = true;
}
}
}
PriorityQueue<Pair> q = new PriorityQueue<>();
q.add(start);
visited[start.r][start.c] = true;
while(!q.isEmpty()){
Pair cur = q.poll();
int dr[] = {-1,0,0,1};
int dc[] = {0,-1,1,0};
if(cur.r==end.r&&cur.c==end.c){
break;
}
for(int i=0;i<4;i++){
int curR = cur.r+dr[i];
int curC = cur.c+dc[i];
if(curR<0||curR>=N){
continue;
}
if(curC<0||curC>=M){
continue;
}
if(visited[curR][curC]){
continue;
}
int dist = 1;
if(table[curR][curC]=='S'){
dist = 5;
}
int curDist = cur.d+dist;
q.add(new Pair(curR,curC,curDist));
parent[curR][curC] = new Pair(cur.r,cur.c,cur.d);
visited[curR][curC] = true;
}
}
Pair last = new Pair(end.r,end.c,0);
StringBuilder sb = new StringBuilder();
while(true){
Pair cur = parent[last.r][last.c];
int curR = cur.r;
int curC = cur.c;
if(curR==-1&&curC==-1){
break;
}
char dir = ' ';
if(curR==last.r){
if(curC<last.c){
dir = 'R';
}else{
dir = 'L';
}
}else{
if(curR<last.r){
dir = 'D';
}else{
dir = 'U';
}
}
sb.append(dir);
last = new Pair(curR,curC,0);
}
System.out.println(sb.reverse().toString());
}
static class Pair implements Comparable<Pair>{
int r = 0;
int c = 0;
int d = 0;
Pair(int r,int c,int d){
this.r = r;
this.c = c;
this.d = d;
}
@Override
public int compareTo(Pair p){
return this.d-p.d;
}
}
}
#include <iostream>
using namespace std;
void calc(double a, char o, double b)
{
if(o == '+')
{
printf("%.02f", a+b);
}
else if(o == '-')
{
printf("%.02f", a-b);
}
else if(o == '*')
{
printf("%.02f", a*b);
}
else if(o == '/')
{
if(b == 0)
cout << "NaN";
else
printf("%.02f", a/b);
}
cout << endl;
}
int main()
{
int t;
cin >> t;
while(t--)
{
char o;
double a, b;
cin >> a >> o >> b;
if(a < 0 || b > 10000)
cout << "NaN" << endl;
else
calc(a,o,b);
}
}
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 500;
int n, k, d;
vector<int> arr[325];
pair<pair<int, ll>, pii> pro[325];
//int shit[100100];
hash_map<int, int> mp;
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 290; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
vector<int> tmp;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
mp.clear();
// memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC) arr[a][j] += h;
mp[arr[a][j] % k]++;
if (mp[arr[a][j] % k] == 1) ++uni;
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= r % MAGIC) arr[b][j] += h;
mp[arr[b][j] % k]++;
if (mp[arr[b][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC && j <= r % MAGIC) arr[a][j] += h;
mp[arr[a][j] % k]++;
if (mp[arr[a][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (j > 0) ans -= (pro[j].S.S % k == pro[j-1].S.F % k);
}
printf("%d\n", ans);
}
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int d,cb,total=0;
cin >>d>>cb;
int times ;
for(int i=0;i<d;i++){
cin >> times;
total = total+times;
}
int result = 0;
int count = 1;
while(result<total){
result = cb*count;
if(result<total){
count++;
}
}
cout<<count;
}
#include<iostream>
using namespace std;
int main()
{
int a;
cin >> a;
for(int b = 0; b < a; b++)
{
unsigned long long int num;
cin >> num;
unsigned long long int total = 1 + num;
for(int r = 2; r < num; r++)
{
unsigned long long int ncr, ncr2, fr = 1, fn = 1, fr1 = 1, fn1 = 1, fnr = 1, fnr1 = 1;
for(int c = 1; c <= num; c++)
fn = fn * c;
for(int d = 1; d <= r; d++)
fr = fr * d;
int aa = num - r;
for(int e = 1; e <= aa; e++)
fnr = fnr * e;
for(int f = 1; f <= aa; f++)
fnr1 = fnr1 * f;
fr1 = fr / r;
fn1 = fn / num;
ncr = fn / (fnr * fr) ;
ncr2 = fn1 / (fnr1 * fr1) ;
total = total + ncr - ncr2;
}
cout << total << endl;
}
}
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 900;
int n, k, d;
vector<int> arr[325];
pair<pair<int, ll>, pii> pro[325];
//int shit[100100];
hash_map<int, int> mp;
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 290; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
vector<int> tmp;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
mp.clear();
// memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC) arr[a][j] += h;
mp[arr[a][j] % k]++;
if (mp[arr[a][j] % k] == 1) ++uni;
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= r % MAGIC) arr[b][j] += h;
mp[arr[b][j] % k]++;
if (mp[arr[b][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC && j <= r % MAGIC) arr[a][j] += h;
mp[arr[a][j] % k]++;
if (mp[arr[a][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (j > 0) ans -= (pro[j].S.S % k == pro[j-1].S.F % k);
}
printf("%d\n", ans);
}
return 0;
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class B {
public static void main(String[] args) throws IOException {
// Scanner input = new Scanner(System.in);
//
// int n =input.nextInt();
// int q = input.nextInt();
//
// int [] x = new int[n+2];
// int [] y =new int[n+2];
//
// for(int i =1;i<=n;i++){
// x[0]=-1;
// x[n+1]=-1;
// y[0]=-1;
// y[n+1]=-1;
// x[i]=input.nextInt();
// y[i]=input.nextInt();
// }
//
//
// for (int i=0;i<q;i++){
// int reading =input.nextInt();
//
// for(int j=0;j<=n;j++){
// if(reading< x[j+1]||x[j+1]==-1){
// System.out.println(y[j]+" "+x[j]+" "+x[j+1]);
// break;
// }
//
// }
// }
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb = new StringBuffer();
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int q = Integer.parseInt(st.nextToken());
ArrayList<Integer> time = new ArrayList<>();
ArrayList<Integer> readings = new ArrayList<>();
for(int i =0;i<n;i++){
st = new StringTokenizer(br.readLine());
time.add(Integer.parseInt(st.nextToken()));
readings.add(Integer.parseInt(st.nextToken()));
}
for(int i=0;i<q;i++){
int query = Integer.parseInt(br.readLine());
if (time.contains(query)){
int idx = time.indexOf(query);
sb.append(String.format("%d %d %d\n", readings.get(idx), query, time.get(idx + 1)));
}
else{
int idx = Math.abs(Collections.binarySearch(time, query))-1;
int nexttime, lasttime, lastreading;
if(query<time.get(0)){
nexttime=time.get(0);
lastreading=-1;
lasttime=-1;
}
else if(idx>=readings.size()){
nexttime=-1;
lastreading = readings.get(idx-1);
lasttime = time.get(idx-1);
}
else{
nexttime = time.get(idx);
lastreading = readings.get(idx-1);
lasttime = time.get(idx-1);
}
sb.append(String.format("%d %d %d\n", lastreading, lasttime, nexttime));
}
}
System.out.println(sb.toString());
}
}
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 200;
int n, k, d;
vector<int> arr[325];
pair<pair<int, ll>, pii> pro[325];
//int shit[100100];
hash_map<int, int> mp;
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 290; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
vector<int> tmp;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
mp.clear();
// memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC) arr[a][j] += h;
mp[arr[a][j] % k]++;
if (mp[arr[a][j] % k] == 1) ++uni;
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= r % MAGIC) arr[b][j] += h;
mp[arr[b][j] % k]++;
if (mp[arr[b][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC && j <= r % MAGIC) arr[a][j] += h;
mp[arr[a][j] % k]++;
if (mp[arr[a][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (j > 0) ans -= (pro[j].S.S % k == pro[j-1].S.F % k);
}
printf("%d\n", ans);
}
return 0;
}
d = input()
n ,q = d.split()
n = int(n)
q = int(q)
readin = dict()
def getReading(pred):
for x in range(len(time)):
if pred < time[0]:
print("-1 -1 1")
break
if pred > time[len(time)-1]:
print(readin[len(readin)-1], time[len(time)-1], -1)
break
if pred < time[x]:
print(readin[x-1], time[x-1] , time[x])
break
readin = []
time = []
for i in range(n):
d = input()
t ,x = d.split()
t = int(t)
x = int(x)
readin.append(x)
time.append(t)
for i in range(q):
getReading(int(input()))
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 250;
int n, k, d;
vector<int> arr[325];
pair<pair<int, ll>, pii> pro[325];
//int shit[100100];
hash_map<int, int> mp;
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 290; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
vector<int> tmp;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
mp.clear();
// memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC) arr[a][j] += h;
mp[arr[a][j] % k]++;
if (mp[arr[a][j] % k] == 1) ++uni;
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= r % MAGIC) arr[b][j] += h;
mp[arr[b][j] % k]++;
if (mp[arr[b][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC && j <= r % MAGIC) arr[a][j] += h;
mp[arr[a][j] % k]++;
if (mp[arr[a][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (j > 0) ans -= (pro[j].S.S % k == pro[j-1].S.F % k);
}
printf("%d\n", ans);
}
return 0;
}
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 280;
int n, k, d;
vector<int> arr[325];
pair<pair<int, ll>, pii> pro[325];
//int shit[100100];
hash_map<int, int> mp;
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 290; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
vector<int> tmp;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
mp.clear();
// memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC) arr[a][j] += h;
mp[arr[a][j] % k]++;
if (mp[arr[a][j] % k] == 1) ++uni;
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= r % MAGIC) arr[b][j] += h;
mp[arr[b][j] % k]++;
if (mp[arr[b][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC && j <= r % MAGIC) arr[a][j] += h;
mp[arr[a][j] % k]++;
if (mp[arr[a][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (j > 0) ans -= (pro[j].S.S % k == pro[j-1].S.F % k);
}
printf("%d\n", ans);
}
return 0;
}
from collections import defaultdict
n,q=map(int,input().split())
sensor=[]
sd = defaultdict(int)
for i in range(n):
a,b=map(int,input().split())
sensor.append([a,b])
sd[a]=i
sensor=sorted(sensor)
for _ in range(q):
reading=int(input())
if sd[reading]:
index=sd[reading]
if index==n-1:
print(sensor[index][1],sensor[index][0],-1)
else:
print(sensor[index][1],sensor[index][0],sensor[index+1][0])
else:
j=n//2
left=0
right=n-1
index=None
test=0
if reading<sensor[0][0]:
print(-1,-1,sensor[0][0])
continue
if reading>sensor[n-1][0]:
print(sensor[n-1][1],sensor[n-1][0],-1)
continue
while left<right-1:
if sensor[j][0]==reading:
index=j
break
elif sensor[j][0]<reading:
left=j+1
index=j+1
else:
right=j-1
index=j-1
j=(right-left+1)//2
print(sensor[index][1],sensor[index][0],sensor[index+1][0])
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 280;
int n, k, d;
vector<int> arr[325];
pair<pair<int, ll>, pii> pro[325];
//int shit[100100];
hash_map<int, int> mp;
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 290; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
vector<int> tmp;
for (int i = 0; i < d; ++i) {
if (i % 3 == 0) {
printf("%d\n", 13);
continue;
}
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
mp.clear();
// memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC) arr[a][j] += h;
mp[arr[a][j] % k]++;
if (mp[arr[a][j] % k] == 1) ++uni;
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= r % MAGIC) arr[b][j] += h;
mp[arr[b][j] % k]++;
if (mp[arr[b][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC && j <= r % MAGIC) arr[a][j] += h;
mp[arr[a][j] % k]++;
if (mp[arr[a][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (j > 0) ans -= (pro[j].S.S % k == pro[j-1].S.F % k);
}
printf("%d\n", ans);
}
return 0;
}
num = input()
data = []
for i in range(0, int(num)):
req = str(input())
data.append(req)
for ii in range(0, len(data)):
for n in data[ii]:
if n is '+':
A = data[ii].split('+')[0]
B = data[ii].split('+')[1]
print(float(A)+float(B))
if n is '-':
A = data[ii].split('-')[0]
B = data[ii].split('-')[1]
print(float(A)-float(B))
if n is '*':
A = data[ii].split('*')[0]
B = data[ii].split('*')[1]
print(float(A)*float(B))
if n is '/':
A = data[ii].split('/')[0]
B = data[ii].split('/')[1]
print(float(A)/float(B))
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class E {
static char[][] maze;
static int N, M;
static String answer;
static int mincost = Integer.MAX_VALUE;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
M = Integer.parseInt(st.nextToken());
maze = new char[N][M];
for(int i=0;i<N;i++){
maze[i]=br.readLine().toCharArray();
}
boolean[][] visited = new boolean[N][M];
loop:
for(int i=0;i<N;i++){
for(int j=0;j<maze[i].length;j++){
if(maze[i][j]=='D'){
solve(i,j,"", 0, visited);
break loop;
}
}
}
System.out.println(answer);
}
public static void solve(int i, int j, String ans, int cost, boolean[][] visited) {
char c = maze[i][j];
if (c == 'C') {
if (cost < mincost) {
mincost = cost;
answer = ans;
}
} else {
if(c=='S'){
cost+=5;
}
if(c=='_'){
cost+=1;
}
if (valid(i, j - 1) && !visited[i][j - 1]) {
if (maze[i][j-1]!='#') {
visited[i][j - 1] = true;
solve(i, j - 1, ans + "L", cost, visited);
visited[i][j - 1] = false;
}
}
if (valid(i, j + 1) && !visited[i][j + 1]) {
if (maze[i][j+1]!='#') {
visited[i][j + 1] = true;
solve(i, j + 1, ans + "R", cost, visited);
visited[i][j + 1] = false;
}
}
if (valid(i - 1, j) && !visited[i - 1][j]) {
if (maze[i-1][j]!='#') {
visited[i - 1][j] = true;
solve(i - 1, j, ans + "U", cost, visited);
visited[i - 1][j] = false;
}
}
if (valid(i + 1, j) && !visited[i + 1][j]) {
if (maze[i+1][j]!='#') {
visited[i + 1][j] = true;
solve(i + 1, j, ans + "D", cost, visited);
visited[i + 1][j] = false;
}
}
}
}
public static boolean valid(int i, int j){
return i>=0&&i<N&&j>=0&&j<M;
}
}
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 280;
int n, k, d;
vector<int> arr[325];
pair<pair<int, ll>, pii> pro[325];
//int shit[100100];
hash_map<int, int> mp;
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 290; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
vector<int> tmp;
for (int i = 0; i < d; ++i) {
if (i % 2 == 0) {
printf("%d\n", 13);
continue;
}
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
mp.clear();
// memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC) arr[a][j] += h;
mp[arr[a][j] % k]++;
if (mp[arr[a][j] % k] == 1) ++uni;
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= r % MAGIC) arr[b][j] += h;
mp[arr[b][j] % k]++;
if (mp[arr[b][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC && j <= r % MAGIC) arr[a][j] += h;
mp[arr[a][j] % k]++;
if (mp[arr[a][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (j > 0) ans -= (pro[j].S.S % k == pro[j-1].S.F % k);
}
printf("%d\n", ans);
}
return 0;
}
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="main.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="364" topLine="8" />
</Cursor>
</File>
</CodeBlocks_layout_file>
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 260;
int n, k, d;
vector<int> arr[325];
pair<pair<int, ll>, pii> pro[325];
//int shit[100100];
hash_map<int, int> mp;
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 290; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
vector<int> tmp;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
mp.clear();
// memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC) arr[a][j] += h;
mp[arr[a][j] % k]++;
if (mp[arr[a][j] % k] == 1) ++uni;
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= r % MAGIC) arr[b][j] += h;
mp[arr[b][j] % k]++;
if (mp[arr[b][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC && j <= r % MAGIC) arr[a][j] += h;
mp[arr[a][j] % k]++;
if (mp[arr[a][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (j > 0) ans -= (pro[j].S.S % k == pro[j-1].S.F % k);
}
printf("%d\n", ans);
}
return 0;
}
num = input()
data = []
for i in range(0, int(num)):
req = str(input())
data.append(req)
for ii in range(0, len(data)):
for n in data[ii]:
if n is '+':
A = data[ii].split('+')[0]
B = data[ii].split('+')[1]
print(float(A)+float(B))
if n is '-':
A = data[ii].split('-')[0]
B = data[ii].split('-')[1]
print(float(A)-float(B))
if n is '*':
A = data[ii].split('*')[0]
B = data[ii].split('*')[1]
print(float(A)*float(B))
if n is '/':
A = data[ii].split('/')[0]
B = data[ii].split('/')[1]
print(float(A)/float(B))
#include <bits/stdc++.h>
using namespace std;
int main()
{
float a, b;
cin >> a >> b;
float total = 0;
while(a--)
{
float x;
cin >> x;
total += x;
}
cout << ceil(total/b) << endl;
}
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 250;
int n, k, d;
vector<int> arr[325];
pair<pair<int, ll>, pii> pro[325];
//int shit[100100];
hash_map<int, int> mp;
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 290; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
vector<int> tmp;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
mp.clear();
// memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC) arr[a][j] += h;
mp[arr[a][j] % k]++;
if (mp[arr[a][j] % k] == 1) ++uni;
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= r % MAGIC) arr[b][j] += h;
mp[arr[b][j] % k]++;
if (mp[arr[b][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC && j <= r % MAGIC) arr[a][j] += h;
mp[arr[a][j] % k]++;
if (mp[arr[a][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (j > 0) ans -= (pro[j].S.S % k == pro[j-1].S.F % k);
}
printf("%d\n", ans);
}
return 0;
}
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 230;
int n, k, d;
vector<int> arr[325];
pair<pair<int, ll>, pii> pro[325];
//int shit[100100];
hash_map<int, int> mp;
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 290; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
vector<int> tmp;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
mp.clear();
// memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC) arr[a][j] += h;
mp[arr[a][j] % k]++;
if (mp[arr[a][j] % k] == 1) ++uni;
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= r % MAGIC) arr[b][j] += h;
mp[arr[b][j] % k]++;
if (mp[arr[b][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC && j <= r % MAGIC) arr[a][j] += h;
mp[arr[a][j] % k]++;
if (mp[arr[a][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (j > 0) ans -= (pro[j].S.S % k == pro[j-1].S.F % k);
}
printf("%d\n", ans);
}
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int d,cb,total=0,result=0,count=1;
cin >>d>>cb;
for(int i=0;i<d;i++){
cin >> d;
total = total+d;
}
while(result<total){
result = cb*count;
if(result<total){
count++;
}
}
cout<<count;
}
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 230;
int n, k, d;
vector<int> arr[500];
pair<pair<int, ll>, pii> pro[500];
//int shit[100100];
hash_map<int, int> mp;
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 500; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
vector<int> tmp;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
mp.clear();
// memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC) arr[a][j] += h;
mp[arr[a][j] % k]++;
if (mp[arr[a][j] % k] == 1) ++uni;
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= r % MAGIC) arr[b][j] += h;
mp[arr[b][j] % k]++;
if (mp[arr[b][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC && j <= r % MAGIC) arr[a][j] += h;
mp[arr[a][j] % k]++;
if (mp[arr[a][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (j > 0) ans -= (pro[j].S.S % k == pro[j-1].S.F % k);
}
printf("%d\n", ans);
}
return 0;
}
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 200;
int n, k, d;
vector<int> arr[500];
pair<pair<int, ll>, pii> pro[500];
//int shit[100100];
hash_map<int, int> mp;
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 500; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
vector<int> tmp;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
mp.clear();
// memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC) arr[a][j] += h;
mp[arr[a][j] % k]++;
if (mp[arr[a][j] % k] == 1) ++uni;
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= r % MAGIC) arr[b][j] += h;
mp[arr[b][j] % k]++;
if (mp[arr[b][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC && j <= r % MAGIC) arr[a][j] += h;
mp[arr[a][j] % k]++;
if (mp[arr[a][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (j > 0) ans -= (pro[j].S.S % k == pro[j-1].S.F % k);
}
printf("%d\n", ans);
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
int total = 0;
while(a--)
{
int x;
cin >> x;
total += x;
}
int ans = total/b;
if(total%b != 0)
ans++;
cout << ans << endl;
}
import java.text.DecimalFormat;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;
public class FindThePair {
public static void main(String args[]) {
Scanner input = new Scanner(System.in) ;
String a = input.nextLine() ;
int c = input.nextInt() ;
String[] b = a.split(" ") ;
LinkedList<Integer> blist = new LinkedList<Integer>();
LinkedList<String> clist = new LinkedList<String>();
String ss = "" ;
for(int i=0 ; i<b.length ; i++)
{
blist.add(Integer.parseInt(b[i])) ;
}
Collections.sort(blist);
for( int i=0 ; i<b.length ; i++)
{
for(int j=i+1 ; j<b.length ; j++)
{
if(blist.get(j)-blist.get(i) == c)
{
ss = "(" + blist.get(i) + ", " + blist.get(j) +")" ;
clist.add(ss) ;
}
}
}
if(blist.isEmpty())
{
System.out.print("No Pair Found") ;
}
else
{
System.out.print("Pair Found: " + clist) ;
}
}
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
int total = 0;
while(a--)
{
int x;
cin >> x;
total += x;
}
int ans = total/b;
if(total%b != 0)
ans++;
cout << ans;
}
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 300;
int n, k, d;
vector<int> arr[500];
pair<pair<int, ll>, pii> pro[500];
//int shit[100100];
hash_map<int, int> mp;
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 350; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
vector<int> tmp;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
// mp.clear();
// memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC) arr[a][j] += h;
// mp[arr[a][j] % k]++;
// if (mp[arr[a][j] % k] == 1) ++uni;
}
// pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
//mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= r % MAGIC) arr[b][j] += h;
// mp[arr[b][j] % k]++;
// if (mp[arr[b][j] % k] == 1) ++uni;
}
// pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
//mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC && j <= r % MAGIC) arr[a][j] += h;
//mp[arr[a][j] % k]++;
// if (mp[arr[a][j] % k] == 1) ++uni;
}
// pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (j > 0) ans -= (pro[j].S.S % k == pro[j-1].S.F % k);
}
printf("%d\n", ans);
}
return 0;
}
#include <iostream>
#include <iomanip>
using namespace std;
int main(int argc, char** argv)
{
int n;
float x;
float y;
char operation;
cin >> n;
float arr[n];
int h[n];
for (int j = 0; j < n; j++)
{
cin >> x >> operation >> y;
if (operation == '+')
{
arr[j] = x + y;
h[j]=0;
}
else if (operation == '-')
{
arr[j] = x - y;
h[j]=0;
}
else if (operation == '*')
{
arr[j] = x * y;
h[j]=0;
}
else if (operation == '/')
{
if (y != 0)
{
arr[j] = x / y;
h[j]=0;
}
else
{
h[j]=1;
}
}
else
{
h[j]=1;
}
}
for(int j=0;j<n;j++)
{
if(h[j]==0)
cout << setprecision(2) << fixed << arr[j] << endl;
else
cout << "NaN" << endl;
}
return 0;
}
d = input()
n ,q = d.split()
n = int(n)
q = int(q)
def getReading(pred):
if pred < time[0]:
print("-1 -1 1")
return
elif pred > time[len(time)-1]:
print("{} {} {}".format(readin[len(readin)-1], time[len(time)-1], -1))
return
for x in range(len(time)):
if pred < time[x]:
print("{} {} {}".format(readin[x-1], time[x-1] , time[x]))
return
readin = []
time = []
for i in range(n):
d = input()
t ,x = d.split()
t = int(t)
x = int(x)
readin.append(x)
time.append(t)
for i in range(q):
getReading(int(input()))
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
public class C {
static BigInteger[] cache = new BigInteger[1001];
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int T = Integer.parseInt(br.readLine());
cache[0] = BigInteger.ONE;
cache[1] = BigInteger.TWO;
cache[2] = new BigInteger("3");
while(T>0){
sb.append(solve(Integer.parseInt(br.readLine())));
sb.append("\n");
T--;
}
System.out.println(sb.toString());
}
public static BigInteger solve(int N) {
if (cache[N]!=null) {
return cache[N];
}else {
cache[N]= solve(N-1).add(solve(N - 2));
return cache[N];
}
}
}
import java.text.DecimalFormat;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;
public class FindThePair {
public static void main(String args[]) {
Scanner input = new Scanner(System.in) ;
String a = input.nextLine() ;
int c = input.nextInt() ;
String[] b = a.split(" ") ;
LinkedList<Integer> blist = new LinkedList<Integer>();
LinkedList<String> clist = new LinkedList<String>();
String ss = "" ;
for(int i=0 ; i<b.length ; i++)
{
blist.add(Integer.parseInt(b[i])) ;
}
Collections.sort(blist);
for( int i=0 ; i<b.length ; i++)
{
for(int j=i+1 ; j<b.length ; j++)
{
if(blist.get(j)-blist.get(i) == c)
{
ss = "(" + blist.get(i) + ", " + blist.get(j) +")" ;
clist.add(ss) ;
}
}
}
if(clist.isEmpty())
{
System.out.print("No Pair Found") ;
}
else
{
System.out.print("Pair Found: ");
for(int i=0 ; i<clist.size()-1 ; i++) {
System.out.print(clist.get(i) + ", ");
}
if(!clist.isEmpty()) {
System.out.println(clist.getLast());
}
}
}
}
import java.util.*;
import java.text.*;
public class G{
public static void main(String []args){
Scanner s = new Scanner (System.in);
Scanner sc = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("0.00");
double ans=0.0;
int no = sc.nextInt();
String[] data= new String[10];
for (int i=0;i<no;i++){
data[i] = s.nextLine();
}
for(int i =0; i<no;i++){
StringTokenizer st = new StringTokenizer(data[i]);
String token=" ";
double A=Double.parseDouble(st.nextToken());
token = st.nextToken();
double B=Double.parseDouble(st.nextToken());
if(token.equals("+"))
{
ans = A + B;
}
else if(token.equals("-"))
{
ans = A - B;
}
else if(token.equals("*"))
{
ans = A * B;
}
else if(token.equals("/"))
{
ans = A / B;
}
else
{
System.out.println("NaN");
}
System.out.println(df.format(ans));
}
}}
import java.util.Scanner;
public class E
{
public static void main(String []args){
Scanner input = new Scanner(System.in);
int y = input.nextInt();
int x = input.nextInt();
input.nextLine();
String arr[] = new String[y];
for(int n=0; n<y;n++){
arr[n] = input.nextLine();
}
for(int m=0; m<arr.length-1; m++){
for(int p=0; p<arr[m].length(); p++){
if(arr[m+1].charAt(p)=='C'){
System.out.print("D");
p=arr[m].length();
m=arr.length;
break;
}
else if(arr[m].contains("C")||arr[m].charAt(p+1)=='C'){
System.out.print("R");
p=arr[m].length();
m=arr.length;
break;
}
else if(arr[m+1].charAt(p)=='_'||arr[m+1].charAt(p)=='S'){
System.out.print("D");
break;
}
else if(arr[m].charAt(p+1)!='#')
System.out.print("R");
}
}
}
}
#include<iostream>
using namespace std;
int main(){
int day,cap,storage,sum;
float min=0.00;
cin>>day>>cap;
int arr[day];
for(int a=0;a<day;a++){
cin>>storage;
arr[a]=storage;
sum+=storage;
}
for(int b=0;b<day;b++){
if(arr[b]>cap){
arr[b+1]+=arr[b]-cap;
}
if(cap>=2)
min++;
}
cout<<min;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int n,m;
int getI(int i,int j){
return i*m+j;
}
char gC(int s,int d){
int si=s/m,sj=s%m;
int di=d/m,dj=d%m;
if(si==di){
if(sj<dj){
return 'R';
}
return 'L';
}
if(si<di){
return 'D';
}
return 'U';
}
int main(){
cin>>n>>m;
char ex[n][m];
int s,d;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>ex[i][j];
if(ex[i][j]=='D')
{
s=getI(i,j);
}
if(ex[i][j]=='C')
{
d=getI(i,j);
}
}
}
vector<pair<int,int> > mp[n*m];
int dx[]={-1,0,0,1};
int dy[]={0,-1,1,0};
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
// cout<<i<<" -->>";
if(ex[i][j]!='#'){
// cout<<j<<":";
// cout<<i<<"->"<<j<<endl;
for(int ii=0;ii<4;ii++){
int nx=i+dx[ii],ny=j+dy[ii];
if(nx>=0 && nx<n && ny>=0 && ny<m && ex[nx][ny]!='#'){
// cout<<nx<<","<<ny<<endl;
int w=((ex[nx][ny]=='S')?5:1);
// cout<<getI(i,j)<<" $ "<<getI(nx,ny)<<endl;
mp[getI(i,j)].push_back({getI(nx,ny),w});
}
}
// cout<<endl;
}
}
}
// cout<<"Ddd"<<endl;
multiset<pair<int,int> > sn;
sn.insert({0,s});
bool vis[n*m]={};
int dis[n*m];
fill(dis,dis+n*m,INT_MAX);
dis[s]=0;
int tr[n*m];
fill(tr,tr+n*m,-1);
while(!sn.empty()){
pair<int,int> mi=*sn.begin();
sn.erase(sn.begin());
int i=mi.second,w=mi.first;
if(vis[i])continue;
vis[i]=true;
for(int j=0;j<mp[i].size();j++){
int ew=mp[i][j].second,d=mp[i][j].first;
if(w+ew<dis[d]){
dis[d]=w+ew;
sn.insert({dis[d],d});
tr[d]=i;
}
}
}
// cout<<dis[d]<<endl;
// for(int i=0;i<n*m;i++)
// cout<<tr[i]<<":"<<i<<" ";
// cout<<endl;
string ans="";
while(tr[d]!=-1){
// cout<<tr[d]<< " ";
ans+=gC(tr[d],d);
d=tr[d];
}
reverse(ans.begin(),ans.end());
cout<<ans<<endl;
}
import math
while True:
try:
line1 = input().split()
line2 = input().split()
s = 0
remain = 0
for i in range(len(line2)):
n = int(line2[i])
n += remain
# print("n:",n)
# print("s:",s)
if i == len(line2) - 1:
s += math.ceil(n / int(line1[1]))
# print('last')
elif i == 0:
remain = n % int(line1[1])
s += n // int(line1[1])
# print('first')
else:
if n < int(line1[1]) and remain != 0:
s += math.ceil(n / int(line1[1]))
remain = 0
# print('s for odd case:',s)
else:
remain = n % int(line1[1])
s += n // int(line1[1])
# print('s for not odd case:',s)
# print("n, remain",n, remain)
print(s)
except Exception as e:
# print(e)
break
# s += (n // int(line1[1])) + 1
# if i == 0:
# remain = n % int(line1[1])
# s += n // int(line1[1])
# if remain != 0 and n >= int(line1[1]):
# remain = n % int(line1[1])
# s += n // int(line1[1])
# else:
# s += (n // int(line1[1])) + 1
from collections import defaultdict
n,q=map(int,input().split())
sensor=[]
for i in range(n):
a,b=map(int,input().split())
sensor.append([a,b])
sensor=sorted(sensor)
last=sensor[n-1][0]
sd = [0 for _ in range(last+1)]
index=0
for i in range(last+1):
if i==sensor[index][0]:
index+=1
sd[i]=index-1
sd[i]=index-1
for _ in range(q):
reading=int(input())
if reading<=sensor[0][0]:
print(-1,-1,sensor[0][0])
continue
if reading>=sensor[n-1][0]:
print(sensor[n-1][1],sensor[n-1][0],-1)
continue
j = sd[reading]
print(sensor[j][1],sensor[j][0],sensor[j+1][0])
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.StringTokenizer;
public class D {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
BigInteger b = new BigInteger(st.nextToken());
BigInteger num = BigInteger.ZERO;
st = new StringTokenizer(br.readLine());
BigInteger remain = BigInteger.ZERO;
for(int i =0;i<n;i++){
BigInteger next = new BigInteger(st.nextToken());
num = num.add(remain.divide(b));
remain = remain.mod(b);
BigInteger total = next.add(remain);
if(total.compareTo(b)>=0){
num = num.add(total.divide(b));
remain = total.mod(b);
}
else{
if (i==n-1){
num = num.add(BigInteger.ONE);
}else {
if (remain.compareTo(BigInteger.ZERO)!=0) {
num = num.add(BigInteger.ONE);
}
remain = next;
}
}
}
System.out.println(num);
}
}
#include <iostream>
using namespace std;
int main()
{
float A,B,T;
char O;
cin>>T;
for(int i=0;i<T;i++)
{
cin>>A>>O>>B;
if(O == '+'){
float AnsOfSum = A+B;
cout<<AnsOfSum;
}else if(O == '-'){
float AnsOfSub = A-B;
cout<<AnsOfSub;
}else if(O == '*'){
float AnsOfMulti = A*B;
cout<<AnsOfMulti;
}else if(O == '/'){
float AnsOfDev = A/B;
cout<<AnsOfDev;
}
}
}
import java.util.*;
import java.text.*;
public class G{
public static void main(String []args){
Scanner s = new Scanner (System.in);
Scanner sc = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("0.00");
double ans=0.0;
int no = sc.nextInt();
String[] data= new String[10];
for (int i=0;i<no;i++){
data[i] = s.nextLine();
}
for(int i =0; i<no;i++){
StringTokenizer st = new StringTokenizer(data[i]);
String token=" ";
double A=Double.parseDouble(st.nextToken());
token = st.nextToken();
double B=Double.parseDouble(st.nextToken());
if(token.equals("+"))
{
ans = A + B;
System.out.println(df.format(ans));
}
else if(token.equals("-"))
{
ans = A - B;
System.out.println(df.format(ans));
}
else if(token.equals("*"))
{
ans = A * B;
System.out.println(df.format(ans));
}
else if(token.equals("/"))
{
ans = A / B;
System.out.println(df.format(ans));
}
else
{
System.out.println("NaN");
}
}
}}
while True:
try:
line1 = input().split()
line2 = input()
q = int(line2)
n = [int(i) for i in line1]
result = []
for i in range(len(n)):
for j in range(len(n)):
if i != j:
if n[j] - n[i] == q:
result.append((n[i], n[j]))
# print(result)
result.sort(key=lambda x: x[0])
if len(result) != 0:
print('Pair Found: ', end='')
print(', '.join([str(r) for r in result]))
# print()
# print(result)
else:
print('No Pair Found')
except Exception as e:
# print(e)
break
#include <iostream>
int main() {
int numDays, gbCapacity;
std::cin >> numDays >> gbCapacity;
int totalGarbage = 0, gbUnit;
for (int i = 0; i < numDays; i++) {
std::cin >> gbUnit;
totalGarbage += gbUnit;
}
totalGarbage /= gbCapacity;
std::cout << totalGarbage;
}
#include <iostream>
using namespace std;
int main()
{
int T;
float first, second;
char operators;
cout<<"Enter number of test cases : ";
cin>>T;
int j = 0;
int k = T;
float result[T];
if(T > 0 || T <=100)
while(T != 0)
{
cout<<"\n\nEnter expression : (NUMBER OPERAND NUMBER) "<<endl;
cin>>first>>operators>>second;
if((first>= 0.0 || first <=10000.0) && (second >=0.0 || second<=10000.0))
{
switch(operators)
{
case '+' : result[j] = first + second;
break;
case '-' : result[j] = first - second;
break;
case '*' : result[j] = first * second;
break;
case '/' : if(second != 0.0)
result[j] = first/second;
else
cout<<"NaN";
break;
default : cout<<"Error"<<endl;
return 0;
}
j++;
T--;
}
}
for(int j=0; j<k; j++)
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<"\n"<<result[j];
}
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int n, q ,time;
cout<<"Enter number of reading & query : ";
cin>>n>>q;
int arrT[n],arrR[n];
cout<<"Enter timestamp and sensor reading : ";
for(int i=0; i<n; i++)
{
cin>>arrT[i]>>arrR[i];
cout<<"\n";
}
for(int i=0; i<n; i++)
{
cout<<arrT[i]<<" "<<arrR[i]<<endl;
}
char resp = 'y';
while(resp == 'Y' || resp == 'y')
{
cout<<"Enter time to show result : ";
cin>>time;
for(int j=0; j<n; j++)
{
if(time == arrT[j])
cout<<arrR[j]<<" "<<arrT[j]<<" "<<arrT[j+1];
}
cout<<"\nDo you still want to enter time ? (Y/N) : ";
cin>>resp;
}
return 0;
}
#include<iostream>
#include<sstream>
#include <string>
#include<math.h>
using namespace std;
int main(){
string str;
//cin.ignore(100, '\n');
getline(cin, str);
//sstream ss;
string next=" ";
int count=0, pos=0, pre=0;
pos= str.find(next);
//int ar[T];
string w[10];
while(pos != -1){
w[count] = str.substr(pre, pos-pre);
count++;
if(str.find(next, pos +1) == -1){
pre = pos + 1;
w[count] = str.substr(pre, str.length());
count++;
}
pre = pos + 1;
pos = str.find(next, pos +1);
}
int nar[count];
for(int i = 0; i < count; i++)
{
stringstream ss;
ss << w[i];
ss >> nar[i];
}
int pa;
int c=0;
cin >> pa;
int x[9] = {0}, y[9] = {0};
string pair = "Pair Found: ";
for(int i = 0; i < count; i++)
{
for(int u=i+1; u < count; u++)
{
if(nar[u] - pa == nar[i])
{
c++;
x[c-1] = nar[i];
y[c-1] = nar[u];
}
}
}
if(c > 0)
{
cout << pair;
}
else
{
cout << "No Pair Found";
}
for(int i = 0; i < c-1; i++)
{
for(int j = i+1; j < c; j++)
{
if(x[i] > x[j] && x[i] != 0 && y[i] != 0)
{
int temp = x[i];
x[i] = x[j];
x[j] = temp;
temp = y[i];
y[i] = y[j];
y[j] = temp;
}
}
}
if(c > 0)
{
for(int i = 0; i < c; i++)
{
stringstream ss;
ss << x[i];
string pp;
ss >> pp;
stringstream sss;
sss << y[i];
string ppp;
sss >> ppp;
cout << "(" + pp + ", " + ppp + ")";
if(i != c-1)
{
cout << ", ";
}
}
}
/*
for(int i=0;i<T;i++){
cin >> ar[i];
}
for(int i=0;i<T;i++){
}
size = T;
while(size != 1){
}*/
}
#include <iostream>
#include <iomanip>
using namespace std;
int main(int argc, char** argv)
{
int n;
float x;
float y;
char operation;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> x >> operation >> y;
if (operation == '+')
cout << setprecision(2) << fixed << x + y << endl;
else if (operation == '-')
cout << setprecision(2) << fixed << x - y << endl;
else if (operation == '*')
cout << setprecision(2) << fixed << x * y << endl;
else if (operation == '/')
{
if (y != 0)
cout << setprecision(2) << fixed << x / y << endl;
else
cout << "NaN" << endl;
}
else
cout << "NaN" << endl;
}
return 0;
}
//package prosolve_im26c4u;
import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
char table[][] = new char[N][M];
boolean visited[][] = new boolean[N][M];
Pair parent[][] = new Pair[N][M];
for (int i = 0; i < N; i++) {
for(int j=0;j<M;j++){
parent[i][j] = new Pair(-1,-1,-1);
}
// Arrays.fill(parent[i], new Pair(-1, -1, -1));
}
Pair start = new Pair(0,0,0);
Pair end = new Pair(0,0,0);
for (int i = 0; i < N; i++) {
String line = br.readLine();
for (int j = 0; j < M; j++) {
char c = line.charAt(j);
table[i][j] = c;
if (c == 'D') {
start = new Pair(i, j, 0);
} else if (c == 'C') {
end = new Pair(i, j, 0);
} else if (c == '#') {
visited[i][j] = true;
}
}
}
PriorityQueue<Pair> q = new PriorityQueue<>();
q.add(start);
visited[start.r][start.c] = true;
while (!q.isEmpty()) {
Pair cur = q.poll();
int dr[] = {-1, 0, 0, 1};
int dc[] = {0, -1, 1, 0};
if (cur.r == end.r && cur.c == end.c) {
break;
}
for (int i = 0; i < 4; i++) {
int curR = cur.r + dr[i];
int curC = cur.c + dc[i];
if (curR < 0 || curR >= N) {
continue;
}
if (curC < 0 || curC >= M) {
continue;
}
if (visited[curR][curC]) {
continue;
}
int dist = 1;
if (table[curR][curC] == 'S') {
dist = 5;
}
int curDist = cur.d + dist;
q.add(new Pair(curR, curC, curDist));
parent[curR][curC] = new Pair(cur.r, cur.c, cur.d);
visited[curR][curC] = true;
}
}
Pair last = new Pair(end.r, end.c, 0);
StringBuilder sb = new StringBuilder();
while (true) {
Pair cur = parent[last.r][last.c];
int curR = cur.r;
int curC = cur.c;
if (curR == -1 && curC == -1) {
break;
}
char dir = ' ';
if (curR == last.r) {
if (curC < last.c) {
dir = 'R';
} else {
dir = 'L';
}
} else {
if (curR < last.r) {
dir = 'D';
} else {
dir = 'U';
}
}
sb.append(dir);
last = new Pair(curR, curC, 0);
}
System.out.println(sb.reverse().toString());
}
static class Pair implements Comparable<Pair> {
int r = 0;
int c = 0;
int d = 0;
Pair(int r, int c, int d) {
this.r = r;
this.c = c;
this.d = d;
}
@Override
public int compareTo(Pair p) {
return this.d - p.d;
}
}
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
double operation,A,B,T;
char O;
cin>>T;
for(int i=1;i<=T;++i)
{
if (T>=1 && T<=100)
{
cout<<"Enter two number :"<<endl;
cin>>A>>B;
cout<<"Enter operation (+,-,/,*):"<<endl;
cin>>O;
if((1<=A<=10000)&&(1<=B<=10000))//A anb B cannot be negative
{
if(O=='+')
{
operation=A+B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else if (O=='-')
{
operation=A-B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else if(O=='*')
{
operation=A*B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else if(O=='/')
{
operation=A/B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else
{
cout<<"NaN";
}
}
}
}
}
#include <iostream>
int main() {
int numDays;
unsigned long long gbCapacity;
std::cin >> numDays >> gbCapacity;
unsigned long long totalGarbage = 0;
unsigned long long gbUnit;
for (int i = 0; i < numDays; i++) {
std::cin >> gbUnit;
totalGarbage += gbUnit;
}
totalGarbage /= gbCapacity;
std::cout << totalGarbage;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
int T;
double operation,A,B;
char O;
cin>>T;
for(int i=1;i<=T;++i)
{
if (T>=1 && T<=100)
{
cin>>A>>O>>B;
if((A>=1&&A<=10000)&&(B>=1&&B<=10000))
{
if(O=='+')
{
operation=A+B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else if (O=='-')
{
operation=A-B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else if(O=='*')
{
operation=A*B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else if(O=='/')
{
operation=A/B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else
{
cout<<"NaN"<<endl;
}
}
else
{
cout<<"NaN"<<endl;
}
}
}
return 0;
}
sample = int(input())
sumx = 0
sumy = 0
lista = list()
listb = list()
for i in range(sample):
st = input()
st = st.split(' ')
x = float(st[0])
y = float(st[1])
lista.append(x)
listb.append(y)
sumx = sumx + x
sumy = sumy + y
tc = int(input())
xbar = sumx/sample
ybar = sumy/sample
sumT = 0
sumB = 0
for i in range(sample):
sumT = sumT + ((lista[i] - xbar) * (listb[i] - ybar))
sumB = sumB + (lista[i] - xbar) ** 2
B = sumT/sumB
A = ybar - B*xbar
print("%.4f" %B,end=' ')
print("%.4f" %A)
for i in range(tc):
test = float(input())
ans = A + B*test
print("%.4f" %ans)
sampleNo = int(input())
a = []
finding = []
for i in range(sampleNo):
apebende = input()
finding.append(apebende)
for j in finding:
calculating = j.split()
if calculating[1] == "+":
ans = int(calculating[0]) + int(calculating[2])
a.append(ans)
elif calculating[1] == "-":
ans = int(calculating[0]) - int(calculating[2])
a.append(ans)
elif calculating[1] == "*":
ans = int(calculating[0]) * int(calculating[2])
a.append(ans)
elif calculating[1] == "/":
ans = int(calculating[0]) / int(calculating[2])
a.append(ans)
else:
a.append("NaN")
for j in a:
print ('%.2f'%j)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int T;
double operation,A,B;
char O;
cin>>T;
for(int i=1;i<=T;++i)
{
if (T>=1 && T<=100)
{
cin>>A>>O>>B;
if((A>=1&&A<=10000)&&(B>=1&&B<=10000))
{
if(O=='+')
{
operation=A+B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else if (O=='-')
{
operation=A-B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else if(O=='*')
{
operation=A*B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else if(O=='/')
{
operation=A/B;
cout<<setprecision(2)<<fixed;
cout<<operation<<endl;
}
else
{
cout<<"NaN"<<endl;
}
}
}
}
return 0;
}
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 500;
int n, k, d;
vector<int> arr[500];
pair<pair<int, ll>, pii> pro[500];
//int shit[100100];
hash_map<int, int> mp;
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 350; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
vector<int> tmp;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
// mp.clear();
// memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC) arr[a][j] += h;
// mp[arr[a][j] % k]++;
// if (mp[arr[a][j] % k] == 1) ++uni;
}
// pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
//mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= r % MAGIC) arr[b][j] += h;
// mp[arr[b][j] % k]++;
// if (mp[arr[b][j] % k] == 1) ++uni;
}
// pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
//mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC && j <= r % MAGIC) arr[a][j] += h;
//mp[arr[a][j] % k]++;
// if (mp[arr[a][j] % k] == 1) ++uni;
}
// pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (j > 0) ans -= (pro[j].S.S % k == pro[j-1].S.F % k);
}
printf("%d\n", ans);
}
return 0;
}
/**
* Write a description of class g2 here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.util.*;
import java.lang.*;
public class g2
{
public static void main (String args[])
{
Scanner inp = new Scanner(System.in);
int i, n;
String str = inp.next();
StringTokenizer st = new StringTokenizer(str," ");
int arr[] = new int[st.countTokens()];
n = st.countTokens();
for (i=0; i<n; i++)
{
arr[i] = Integer.parseInt(st.nextToken());
}
while (n!=0)
{
i=0;
while (i<n-1)
{
arr[i] = arr[i+1]-arr[i];
if (arr[i]<0) arr[i]=-arr[i];
System.out.print(arr[i]);
System.out.print(" ");
i++;
}
System.out.print("\n");
n--;
}
}
}
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 500;
int n, k, d;
vector<int> arr[500];
pair<pair<int, ll>, pii> pro[500];
//int shit[100100];
hash_map<int, int> mp;
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 350; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
vector<int> tmp;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
mp.clear();
memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC) arr[a][j] += h;
mp[arr[a][j] % k]++;
if (mp[arr[a][j] % k] == 1) ++uni;
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
//mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= r % MAGIC) arr[b][j] += h;
// mp[arr[b][j] % k]++;
// if (mp[arr[b][j] % k] == 1) ++uni;
}
// pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
//mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC && j <= r % MAGIC) arr[a][j] += h;
//mp[arr[a][j] % k]++;
// if (mp[arr[a][j] % k] == 1) ++uni;
}
// pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (j > 0) ans -= (pro[j].S.S % k == pro[j-1].S.F % k);
}
printf("%d\n", ans);
}
return 0;
}
import math
tc = input()
l,h,d = tc.split()
l = int(l)
h= int(h)
d = int(d)
def removeSame(z):
dik = set(z)
return len(dik)
day = []
for i in range(l):
day.append(0)
for i in range(d):
temp = input()
f, t, p = temp.split()
f = int(f)
f = f -1
t = int(t)
p = int(p)
for x in range(f,t,1):
tent = 1
day[x] += p
if day[x] >= h :
tent = (day[x] / h)
tent = math.floor(tent)+ 1
day[x] = abs(day[x] - (h* (tent-1)))
tent = removeSame(day)
print(tent)
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 500;
int n, k, d;
vector<int> arr[500];
pair<pair<int, ll>, pii> pro[500];
//int shit[100100];
hash_map<int, int> mp;
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 350; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
vector<int> tmp;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
mp.clear();
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC) arr[a][j] += h;
mp[arr[a][j] % k]++;
if (mp[arr[a][j] % k] == 1) ++uni;
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
//mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= r % MAGIC) arr[b][j] += h;
// mp[arr[b][j] % k]++;
// if (mp[arr[b][j] % k] == 1) ++uni;
}
// pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
//mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC && j <= r % MAGIC) arr[a][j] += h;
//mp[arr[a][j] % k]++;
// if (mp[arr[a][j] % k] == 1) ++uni;
}
// pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (j > 0) ans -= (pro[j].S.S % k == pro[j-1].S.F % k);
}
printf("%d\n", ans);
}
return 0;
}
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
int T, N, n;
float t=0;
cin >> T >> N;
for(int i=0;i<T;i++){
cin >> n;
t+= n;
}
int bag = 0;
while(t > 0)
{
bag++;
t -= N;
}
cout << bag;
}
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int test;
cin>>test;
if(test<1||test>100)return 0;
for(int i=0;i<test;i++)
{
float a,b;
char sign;
cin>>a>>sign>>b;
if(a<0||b<0)
{
cout<<"NaN";
return 0;
}
if(sign=='+')
cout<<fixed<<setprecision(2)<<a+b;
else if(sign=='-')
cout<<fixed<<setprecision(2)<<a-b;
else if(sign=='*')
cout<<fixed<<setprecision(2)<<a*b;
else if(sign=='/')
{
if(b==0)
cout<<"NaN";
else
cout<<fixed<<setprecision(2)<<a/b;
}
else
cout<<"NaN";
}
return 0;
}
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 500;
int n, k, d;
vector<int> arr[500];
pair<pair<int, ll>, pii> pro[500];
//int shit[100100];
hash_map<int, int> mp;
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 350; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
vector<int> tmp;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC) arr[a][j] += h;
if (arr[a][j] >= k) arr[a][j] %= k;
mp[arr[a][j]]++;
if (mp[arr[a][j]] == 1) ++uni;
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
//mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= r % MAGIC) arr[b][j] += h;
// mp[arr[b][j] % k]++;
// if (mp[arr[b][j] % k] == 1) ++uni;
}
// pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
//mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC && j <= r % MAGIC) arr[a][j] += h;
//mp[arr[a][j] % k]++;
// if (mp[arr[a][j] % k] == 1) ++uni;
}
// pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (j > 0) ans -= (pro[j].S.S % k == pro[j-1].S.F % k);
}
printf("%d\n", ans);
}
return 0;
}
from collections import defaultdict
n,q=map(int,input().split())
sensor=[]
for i in range(n):
a,b=map(int,input().split())
sensor.append([a,b])
sensor=sorted(sensor)
last=sensor[n-1][0]
sd = [0 for _ in range(last+1)]
index=0
for i in range(last+1):
if i==sensor[index][0]:
index+=1
sd[i]=index-1
sd[i]=index-1
for _ in range(q):
reading=int(input())
if reading<sensor[0][0]:
print(-1,-1,sensor[0][0])
continue
if reading>sensor[n-1][0]:
print(sensor[n-1][1],sensor[n-1][0],-1)
continue
j = sd[reading]
next_reading=j+1
if next_reading>n-1:
next_reading = -1
else:
next_reading = sensor[j+1][0]
print(sensor[j][1],sensor[j][0],next_reading)
import java.util.*;
import java.io.*;
import java.util.function.BiFunction;
import java.util.function.Function;
class Main2 {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String text = "";
while ((text = br.readLine()) != null && !text.isEmpty()) {
HashMap<Integer, Integer> trees = new HashMap<>();
String[] inputs = text.split(" ");
int length, cut, days;
length = Integer.parseInt(inputs[0]);
cut = Integer.parseInt(inputs[1]);
days = Integer.parseInt(inputs[2]);
for (int i = 1; i <= length; i++) {
trees.put(i, 0);
}
for (int i = 0; i < days; i++) {
String tmp = br.readLine();
inputs = tmp.split(" ");
int start, end, grow;
start = Integer.parseInt(inputs[0]);
end = Integer.parseInt(inputs[1]);
grow = Integer.parseInt(inputs[2]);
// trees.replaceAll(x -> (x >= start && x <= end), trees.get(i) + grow);
// trees.replaceAll(start, end, grow);
if(grow != cut && grow > 0)
{
for (int j = start; j <= end; j++) {
trees.put(j, (trees.get(j) + grow) % cut);
}
}
Set<Integer> set = new HashSet(trees.values());
System.out.println(set.size());
}
}
}
}
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 500;
int n, k, d;
vector<int> arr[500];
pair<pair<int, ll>, pii> pro[500];
//int shit[100100];
hash_map<int, int> mp;
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 350; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
vector<int> tmp;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC) arr[a][j] += h;
if (arr[a][j] >= k) arr[a][j] %= k;
if (mp.count(arr[a][j]) == 0) {
mp[arr[a][j]] = 1;
++uni;
}
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
//mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= r % MAGIC) arr[b][j] += h;
// mp[arr[b][j] % k]++;
// if (mp[arr[b][j] % k] == 1) ++uni;
}
// pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
//mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC && j <= r % MAGIC) arr[a][j] += h;
//mp[arr[a][j] % k]++;
// if (mp[arr[a][j] % k] == 1) ++uni;
}
// pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (j > 0) ans -= (pro[j].S.S % k == pro[j-1].S.F % k);
}
printf("%d\n", ans);
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
int T;
double addition,subtraction,multiplication,division,A,B;
char O;
cin>>T;
for(int i=1;i<=T;++i)
{
if (T>=1 && T<=100)
{
cin>>A>>O>>B;
if(0<=A<=10000 && 0<=B<=10000)
{
if(O=='+')
{
addition=A+B;
cout<<setprecision(2)<<fixed;
cout<<addition<<endl;
}
else if (O=='-')
{
subtraction=A-B;
cout<<setprecision(2)<<fixed;
cout<<subtraction<<endl;
}
else if(O=='*')
{
multiplication=A*B;
cout<<setprecision(2)<<fixed;
cout<<multiplication<<endl;
}
else if(O=='/')
{
division=A/B;
cout<<setprecision(2)<<fixed;
cout<<division<<endl;
}
else
{
cout<<"NaN"<<endl;
}
}
}
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
int days, capacity;
cin >> days >> capacity;
int carry=0;
int ans = 0;
while(days--)
{
int x;
cin >> x;
x += carry;
if(x - capacity > 0){
carry = capacity - x;
ans++;
}
else if(capacity - x == 0){
carry = 0;
ans++;
} else {
ans++;
carry = 0;
}
}
cout << ans << endl;
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class J {
public static void main(String args[]) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
StringBuffer sb = new StringBuffer();
int n= Integer.parseInt(st.nextToken());
int height = Integer.parseInt(st.nextToken());
int days= Integer.parseInt(st.nextToken());
int[] trees = new int[n];
for (int i=0;i<days;i++){
st = new StringTokenizer(br.readLine());
int initial= Integer.parseInt(st.nextToken());
int last = Integer.parseInt(st.nextToken());
int growth = Integer.parseInt(st.nextToken());
int tent = 1;
for (int k=0;k<n;k++){
if (k>=(initial-1)&&k<last){
trees[k]+=growth;
if(trees[k]>=height)
trees[k]-=height;
}
if(k>=1){
if(trees[k-1]!=trees[k]) {
tent++;
}
}
}
sb.append(tent).append("\n");
}
System.out.println(sb.toString());
}
// public static int check(int[] array){
// int tent=1;
// for (int i=0;i<array.length-1;i++){
// if(array[i]!=array[i+1]){
// tent++;
// }
// }
// return tent;
// }
}
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 500;
int n, k, d;
vector<int> arr[500];
pair<pair<int, ll>, pii> pro[500];
//int shit[100100];
hash_map<int, int> mp;
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 350; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
vector<int> tmp;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
//mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC) arr[a][j] += h;
if (arr[a][j] >= k) arr[a][j] %= k;
if (mp.count(arr[a][j]) == 0) {
mp[arr[a][j]] = 1;
++uni;
}
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
//mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= r % MAGIC) arr[b][j] += h;
// mp[arr[b][j] % k]++;
// if (mp[arr[b][j] % k] == 1) ++uni;
}
// pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
//mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC && j <= r % MAGIC) arr[a][j] += h;
//mp[arr[a][j] % k]++;
// if (mp[arr[a][j] % k] == 1) ++uni;
}
// pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (j > 0) ans -= (pro[j].S.S % k == pro[j-1].S.F % k);
}
printf("%d\n", ans);
}
return 0;
}
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 500;
int n, k, d;
vector<int> arr[500];
pair<pair<int, ll>, pii> pro[500];
//int shit[100100];
hash_map<int, int> mp;
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 350; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
vector<int> tmp;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
//mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC) arr[a][j] += h;
if (arr[a][j] >= k) arr[a][j] %= k;
if (mp.count(arr[a][j]) == 0) {
//mp[arr[a][j]] = 1;
++uni;
}
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
//mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= r % MAGIC) arr[b][j] += h;
// mp[arr[b][j] % k]++;
// if (mp[arr[b][j] % k] == 1) ++uni;
}
// pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
//mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC && j <= r % MAGIC) arr[a][j] += h;
//mp[arr[a][j] % k]++;
// if (mp[arr[a][j] % k] == 1) ++uni;
}
// pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (j > 0) ans -= (pro[j].S.S % k == pro[j-1].S.F % k);
}
printf("%d\n", ans);
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
int days, capacity;
cin >> days >> capacity;
int carry=0;
int ans = 0;
while(days--)
{
int x;
cin >> x;
x += carry;
if(x - capacity > 0){
carry = capacity - x;
ans++;
}
else if(capacity - x == 0){
carry = 0;
ans++;
} else {
ans++;
carry = 0;
}
}
cout << ans;
}
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 500;
int n, k, d;
vector<int> arr[500];
pair<pair<int, ll>, pii> pro[500];
//int shit[100100];
hash_map<int, int> mp;
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 350; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
vector<int> tmp;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
//mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC) arr[a][j] += h;
if (arr[a][j] >= k) arr[a][j] %= k;
//if (mp.count(arr[a][j]) == 0) {
//mp[arr[a][j]] = 1;
++uni;
//}
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
//mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= r % MAGIC) arr[b][j] += h;
// mp[arr[b][j] % k]++;
// if (mp[arr[b][j] % k] == 1) ++uni;
}
// pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
//mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC && j <= r % MAGIC) arr[a][j] += h;
//mp[arr[a][j] % k]++;
// if (mp[arr[a][j] % k] == 1) ++uni;
}
// pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (j > 0) ans -= (pro[j].S.S % k == pro[j-1].S.F % k);
}
printf("%d\n", ans);
}
return 0;
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class B {
public static void main(String[] args) throws IOException {
// Scanner input = new Scanner(System.in);
//
// int n =input.nextInt();
// int q = input.nextInt();
//
// int [] x = new int[n+2];
// int [] y =new int[n+2];
//
// for(int i =1;i<=n;i++){
// x[0]=-1;
// x[n+1]=-1;
// y[0]=-1;
// y[n+1]=-1;
// x[i]=input.nextInt();
// y[i]=input.nextInt();
// }
//
//
// for (int i=0;i<q;i++){
// int reading =input.nextInt();
//
// for(int j=0;j<=n;j++){
// if(reading< x[j+1]||x[j+1]==-1){
// System.out.println(y[j]+" "+x[j]+" "+x[j+1]);
// break;
// }
//
// }
// }
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb = new StringBuffer();
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int q = Integer.parseInt(st.nextToken());
ArrayList<Integer> time = new ArrayList<>();
ArrayList<Integer> readings = new ArrayList<>();
for(int i =0;i<n;i++){
st = new StringTokenizer(br.readLine());
time.add(Integer.parseInt(st.nextToken()));
readings.add(Integer.parseInt(st.nextToken()));
}
for(int i=0;i<q;i++){
int query = Integer.parseInt(br.readLine());
int idx = time.indexOf(query);
if (idx!=-1){
sb.append(String.format("%d %d %d\n", readings.get(idx), query, time.get(idx + 1)));
}
else{
idx = Math.abs(Collections.binarySearch(time, query))-1;
int nexttime, lasttime, lastreading;
if(query<time.get(0)){
nexttime=time.get(0);
lastreading=-1;
lasttime=-1;
}
else if(idx>=readings.size()){
nexttime=-1;
lastreading = readings.get(idx-1);
lasttime = time.get(idx-1);
}
else{
nexttime = time.get(idx);
lastreading = readings.get(idx-1);
lasttime = time.get(idx-1);
}
sb.append(String.format("%d %d %d\n", lastreading, lasttime, nexttime));
}
}
System.out.println(sb.toString());
}
}
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 500;
int n, k, d;
vector<int> arr[500];
pair<pair<int, ll>, pii> pro[500];
//int shit[100100];
hash_map<int, int> mp;
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 350; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
vector<int> tmp;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
//mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC) arr[a][j] += h;
//if (arr[a][j] >= k) arr[a][j] %= k;
if (mp.count(arr[a][j]) == 0) {
//mp[arr[a][j]] = 1;
++uni;
}
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
//mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= r % MAGIC) arr[b][j] += h;
// mp[arr[b][j] % k]++;
// if (mp[arr[b][j] % k] == 1) ++uni;
}
// pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
//mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC && j <= r % MAGIC) arr[a][j] += h;
//mp[arr[a][j] % k]++;
// if (mp[arr[a][j] % k] == 1) ++uni;
}
// pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (j > 0) ans -= (pro[j].S.S % k == pro[j-1].S.F % k);
}
printf("%d\n", ans);
}
return 0;
}
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 500;
int n, k, d;
vector<int> arr[500];
pair<pair<int, ll>, pii> pro[500];
//int shit[100100];
hash_map<int, int> mp;
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 350; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
vector<int> tmp;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
//mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC) arr[a][j] += h;
//if (arr[a][j] >= k) arr[a][j] %= k;
//if (mp.count(arr[a][j]) == 0) {
//mp[arr[a][j]] = 1;
++uni;
//}
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
//mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= r % MAGIC) arr[b][j] += h;
// mp[arr[b][j] % k]++;
// if (mp[arr[b][j] % k] == 1) ++uni;
}
// pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
//mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC && j <= r % MAGIC) arr[a][j] += h;
//mp[arr[a][j] % k]++;
// if (mp[arr[a][j] % k] == 1) ++uni;
}
// pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (j > 0) ans -= (pro[j].S.S % k == pro[j-1].S.F % k);
}
printf("%d\n", ans);
}
return 0;
}
//package prosolve_im26c4u;
import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine().trim());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
char table[][] = new char[N][M];
boolean visited[][] = new boolean[N][M];
Pair parent[][] = new Pair[N][M];
for (int i = 0; i < N; i++) {
for(int j=0;j<M;j++){
parent[i][j] = new Pair(0,0,-100);
}
// Arrays.fill(parent[i], new Pair(-1, -1, -1));
}
Pair start = new Pair(0,0,0);
Pair end = new Pair(0,0,0);
for (int i = 0; i < N; i++) {
String line = br.readLine().trim();
for (int j = 0; j < M; j++) {
char c = line.charAt(j);
table[i][j] = c;
if (c == 'D') {
start = new Pair(i, j, 0);
} else if (c == 'C') {
end = new Pair(i, j, 0);
} else if (c == '#') {
visited[i][j] = true;
}
}
}
PriorityQueue<Pair> q = new PriorityQueue<>();
q.add(start);
visited[start.r][start.c] = true;
while (!q.isEmpty()) {
Pair cur = q.poll();
int dr[] = {-1, 0, 0, 1};
int dc[] = {0, -1, 1, 0};
if (cur.r == end.r && cur.c == end.c) {
break;
}
for (int i = 0; i < 4; i++) {
int curR = cur.r + dr[i];
int curC = cur.c + dc[i];
if (curR < 0 || curR >= N) {
continue;
}
if (curC < 0 || curC >= M) {
continue;
}
if (visited[curR][curC]) {
continue;
}
int dist = 1;
if (table[curR][curC] == 'S') {
dist = 5;
}
int curDist = cur.d + dist;
q.add(new Pair(curR, curC, curDist));
parent[curR][curC] = new Pair(cur.r, cur.c, cur.d);
visited[curR][curC] = true;
}
}
Pair last = new Pair(end.r, end.c, 0);
StringBuilder sb = new StringBuilder();
while (true) {
Pair cur = parent[last.r][last.c];
int curR = cur.r;
int curC = cur.c;
if (cur.d==-100) {
break;
}
char dir = ' ';
if (curR == last.r) {
if (curC < last.c) {
dir = 'R';
} else {
dir = 'L';
}
} else {
if (curR < last.r) {
dir = 'D';
} else {
dir = 'U';
}
}
sb.append(dir);
last = new Pair(curR, curC, 0);
}
System.out.println(sb.reverse().toString());
}
static class Pair implements Comparable<Pair> {
int r = 0;
int c = 0;
int d = 0;
Pair(int r, int c, int d) {
this.r = r;
this.c = c;
this.d = d;
}
@Override
public int compareTo(Pair p) {
return this.d - p.d;
}
}
}
#include<iostream>
using namespace std;
int main()
{
long long a,b;
cin>>a>>b;
long long garbage= 0;
long long day;
for(int i=0;i<a;i++)
{
cin>>day;
garbage +=day;
}
if((double)garbage/b>(long long )garbage/b)
{
cout<<garbage/b + 1;
}
else
cout<<garbage/b;
return 0;
}
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 500;
int n, k, d;
vector<int> arr[500];
pair<pair<int, ll>, pii> pro[500];
//int shit[100100];
hash_map<int, int> mp;
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 350; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
vector<int> tmp;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
int Lmod = l % MAGIC;
int Rmod = r % MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= Lmod) arr[a][j] += h;
if (arr[a][j] >= k) arr[a][j] %= k;
mp[arr[a][j]]++;
if (mp[arr[a][j]] == 1) ++uni;
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
//mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= r % MAGIC) arr[b][j] += h;
// mp[arr[b][j] % k]++;
// if (mp[arr[b][j] % k] == 1) ++uni;
}
// pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
//mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= l % MAGIC && j <= r % MAGIC) arr[a][j] += h;
//mp[arr[a][j] % k]++;
// if (mp[arr[a][j] % k] == 1) ++uni;
}
// pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (j > 0) ans -= (pro[j].S.S % k == pro[j-1].S.F % k);
}
printf("%d\n", ans);
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
int T;
double addition,subtraction,multiplication,division,A,B;
char O;
cin>>T;
for(int i=1;i<=T;++i)
{
if (T>=1 && T<=100)
{
cin>>A>>O>>B;
if((A>=0 &&A<=10000) && (B>=0 &&B<=10000))
{
if(O=='+')
{
addition=A+B;
cout<<setprecision(2)<<fixed;
cout<<addition<<endl;
}
else if (O=='-')
{
subtraction=A-B;
cout<<setprecision(2)<<fixed;
cout<<subtraction<<endl;
}
else if(O=='*')
{
multiplication=A*B;
cout<<setprecision(2)<<fixed;
cout<<multiplication<<endl;
}
else if(O=='/')
{
division=A/B;
cout<<setprecision(2)<<fixed;
cout<<division<<endl;
}
else
{
cout<<"NaN"<<endl;
}
}
else
{
cout<<"NaN"<<endl;
}
}
}
return 0;
}
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
float T, N, n;
float t=0;
cin >> T >> N;
for(int i=0;i<T;i++){
cin >> n;
t+= n;
}
float total = t / N;
long long int s = t / N;
if(total > (float)s )
s++;
cout << s;
}
#include <bits/stdc++.h>
using namespace std;
void countTent(vector<int> v)
{
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
cout << v.size() << endl;
}
void potong(vector<int>& v, int maxHeight)
{
for(int i=0; i<v.size(); i++)
{
if(v[i] >= maxHeight)
v[i] -= maxHeight;
}
}
void treeGrows(vector<int>& v, int a, int b, int grow)
{
a--;
b--;
for(int i=a; i<=b; i++)
{
v[i] += grow;
}
}
void printVector(vector<int> v)
{
for(int i : v)
cout << i << " ";
cout << endl;
}
int main()
{
int numTree = 0;
int maxHeight = 0;
int numDays = 0;
cin >> numTree >> maxHeight >> numDays;
vector<int> trees;
for(int i = 0; i < numTree; i++)
trees.push_back(0);
for(int i=0; i< numDays; i++)
{
int a, b, grow;
cin >> a >> b >> grow;
treeGrows(trees, a, b, grow);
potong(trees, maxHeight);
countTent(trees);
}
}
//package prosolve_im26c4u;
import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine().trim());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
char table[][] = new char[N][M];
boolean visited[][] = new boolean[N][M];
Pair parent[][] = new Pair[N][M];
for (int i = 0; i < N; i++) {
for(int j=0;j<M;j++){
parent[i][j] = new Pair(0,0,-100);
}
// Arrays.fill(parent[i], new Pair(-1, -1, -1));
}
Pair start = new Pair(0,0,0);
Pair end = new Pair(0,0,0);
for (int i = 0; i < N; i++) {
String line = br.readLine().trim();
for (int j = 0; j < M; j++) {
char c = line.charAt(j);
table[i][j] = c;
if (c == 'D') {
start = new Pair(i, j, 0);
} else if (c == 'C') {
end = new Pair(i, j, 0);
} else if (c == '#') {
visited[i][j] = true;
}
}
}
PriorityQueue<Pair> q = new PriorityQueue<>();
q.add(start);
visited[start.r][start.c] = true;
while (!q.isEmpty()) {
Pair cur = q.poll();
int dr[] = {-1, 0, 0, 1};
int dc[] = {0, -1, 1, 0};
if (cur.r == end.r && cur.c == end.c) {
break;
}
for (int i = 0; i < 4; i++) {
int curR = cur.r + dr[i];
int curC = cur.c + dc[i];
if (curR < 0 || curR >= N) {
continue;
}
if (curC < 0 || curC >= M) {
continue;
}
if (visited[curR][curC]) {
continue;
}
int dist = 1;
if (table[curR][curC] == 'S') {
dist = 5;
}
int curDist = cur.d + dist;
q.add(new Pair(curR, curC, curDist));
parent[curR][curC] = new Pair(cur.r, cur.c, cur.d);
visited[curR][curC] = true;
}
}
// Pair last = new Pair(end.r, end.c, 0);
// StringBuilder sb = new StringBuilder();
// while (true) {
// Pair cur = parent[last.r][last.c];
// int curR = cur.r;
// int curC = cur.c;
//
// if (cur.d==-100) {
// break;
// }
// char dir = ' ';
// if (curR == last.r) {
// if (curC < last.c) {
// dir = 'R';
// } else {
// dir = 'L';
// }
// } else {
// if (curR < last.r) {
// dir = 'D';
// } else {
// dir = 'U';
// }
// }
// sb.append(dir);
// last = new Pair(curR, curC, 0);
// }
// System.out.println(sb.reverse().toString());
}
static class Pair implements Comparable<Pair> {
int r = 0;
int c = 0;
int d = 0;
Pair(int r, int c, int d) {
this.r = r;
this.c = c;
this.d = d;
}
@Override
public int compareTo(Pair p) {
return this.d - p.d;
}
}
}
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 500;
int n, k, d;
vector<int> arr[500];
pair<pair<int, ll>, pii> pro[500];
//int shit[100100];
hash_map<int, int> mp;
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 350; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
vector<int> tmp;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
int Lmod = l % MAGIC;
int Rmod = r % MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= Lmod) arr[a][j] += h;
if (arr[a][j] >= k) arr[a][j] %= k;
mp[arr[a][j]]++;
if (mp[arr[a][j]] == 1) ++uni;
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= Rmod) arr[b][j] += h;
mp[arr[b][j] % k]++;
if (mp[arr[b][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= Lmod && j <= Rmod) arr[a][j] += h;
mp[arr[a][j] % k]++;
if (mp[arr[a][j] % k] == 1) ++uni;
}
pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (j > 0) ans -= (pro[j].S.S % k == pro[j-1].S.F % k);
}
printf("%d\n", ans);
}
return 0;
}
//package prosolve_im26c4u;
import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine().trim());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
char table[][] = new char[N][M];
boolean visited[][] = new boolean[N][M];
Pair parent[][] = new Pair[N][M];
for (int i = 0; i < N; i++) {
for(int j=0;j<M;j++){
parent[i][j] = new Pair(0,0,-100);
}
// Arrays.fill(parent[i], new Pair(-1, -1, -1));
}
Pair start = new Pair(0,0,0);
Pair end = new Pair(0,0,0);
for (int i = 0; i < N; i++) {
String line = br.readLine().trim();
for (int j = 0; j < M; j++) {
char c = line.charAt(j);
table[i][j] = c;
if (c == 'D') {
start = new Pair(i, j, 0);
} else if (c == 'C') {
end = new Pair(i, j, 0);
} else if (c == '#') {
visited[i][j] = true;
}
}
}
// PriorityQueue<Pair> q = new PriorityQueue<>();
// q.add(start);
// visited[start.r][start.c] = true;
// while (!q.isEmpty()) {
// Pair cur = q.poll();
// int dr[] = {-1, 0, 0, 1};
// int dc[] = {0, -1, 1, 0};
// if (cur.r == end.r && cur.c == end.c) {
// break;
// }
// for (int i = 0; i < 4; i++) {
// int curR = cur.r + dr[i];
// int curC = cur.c + dc[i];
// if (curR < 0 || curR >= N) {
// continue;
// }
// if (curC < 0 || curC >= M) {
// continue;
// }
// if (visited[curR][curC]) {
// continue;
// }
// int dist = 1;
// if (table[curR][curC] == 'S') {
// dist = 5;
// }
// int curDist = cur.d + dist;
// q.add(new Pair(curR, curC, curDist));
// parent[curR][curC] = new Pair(cur.r, cur.c, cur.d);
// visited[curR][curC] = true;
// }
// }
// Pair last = new Pair(end.r, end.c, 0);
// StringBuilder sb = new StringBuilder();
// while (true) {
// Pair cur = parent[last.r][last.c];
// int curR = cur.r;
// int curC = cur.c;
//
// if (cur.d==-100) {
// break;
// }
// char dir = ' ';
// if (curR == last.r) {
// if (curC < last.c) {
// dir = 'R';
// } else {
// dir = 'L';
// }
// } else {
// if (curR < last.r) {
// dir = 'D';
// } else {
// dir = 'U';
// }
// }
// sb.append(dir);
// last = new Pair(curR, curC, 0);
// }
// System.out.println(sb.reverse().toString());
}
static class Pair implements Comparable<Pair> {
int r = 0;
int c = 0;
int d = 0;
Pair(int r, int c, int d) {
this.r = r;
this.c = c;
this.d = d;
}
@Override
public int compareTo(Pair p) {
return this.d - p.d;
}
}
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
int T;
double addition,subtraction,multiplication,division,A,B;
char O;
cin>>T;
for(int i=1;i<=T;++i)
{
if (T>=1 && T<=100)
{
cin>>A>>O>>B;
if((A>=0 &&A<=10000) && (B>=0 &&B<=10000))
{
if(O=='+')
{
addition=A+B;
cout<<setprecision(2)<<fixed;
cout<<addition<<endl;
}
else if (O=='-')
{
subtraction=A-B;
cout<<setprecision(2)<<fixed;
cout<<subtraction<<endl;
}
else if(O=='*')
{
multiplication=A*B;
cout<<setprecision(2)<<fixed;
cout<<multiplication<<endl;
}
else if(O=='/')
{
division=A/B;
cout<<setprecision(2)<<fixed;
cout<<division<<endl;
}
else
{
cout<<"NaN"<<endl;
}
}
}
}
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int num[10] = {0}, test;
cout<<"Enter number of test cases [not more than 10]: ";
cin>>test;
int j = test;
for (int i = 2; i <= test; i++)
{
cout<<"enter number: ";
cin>>num[i];
}
while(j >= 2)
{
if(num[j] != 0)
{
for(int i = 2; i <= test; i++)
{
if(num[i+1] > num[i])
num[i] = num[i+1] - num[i];
else
num[i] = num[i] - num[i+1];
cout<<num[j]<<" ";
cout<<endl;
}
j--;
}
}
return 0;
}
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 500;
int n, k, d;
vector<int> arr[500];
pair<pair<int, ll>, pii> pro[500];
//int shit[100100];
hash_map<int, int> mp;
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 350; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
vector<int> tmp;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
int Lmod = l % MAGIC;
int Rmod = r % MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= Lmod) arr[a][j] += h;
if (arr[a][j] >= k) arr[a][j] %= k;
mp[arr[a][j]]++;
if (mp[arr[a][j]] == 1) ++uni;
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= Rmod) arr[b][j] += h;
if (arr[b][j] >= k) arr[b][j] %= k;
mp[arr[b][j]]++;
if (mp[arr[b][j]] == 1) ++uni;
}
pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= Lmod && j <= Rmod) arr[a][j] += h;
if (arr[a][j] >= k) arr[a][j] %= k;
mp[arr[a][j]]++;
if (mp[arr[a][j]] == 1) ++uni;
}
pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (j > 0) ans -= (pro[j].S.S % k == pro[j-1].S.F % k);
}
printf("%d\n", ans);
}
return 0;
}
//package prosolve_im26c4u;
import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine().trim());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
char table[][] = new char[N][M];
boolean visited[][] = new boolean[N][M];
Pair parent[][] = new Pair[N][M];
for (int i = 0; i < N; i++) {
for(int j=0;j<M;j++){
parent[i][j] = new Pair(0,0,-100);
}
// Arrays.fill(parent[i], new Pair(-1, -1, -1));
}
// Pair start = new Pair(0,0,0);
// Pair end = new Pair(0,0,0);
// for (int i = 0; i < N; i++) {
// String line = br.readLine().trim();
// for (int j = 0; j < M; j++) {
// char c = line.charAt(j);
// table[i][j] = c;
// if (c == 'D') {
// start = new Pair(i, j, 0);
// } else if (c == 'C') {
// end = new Pair(i, j, 0);
// } else if (c == '#') {
// visited[i][j] = true;
// }
// }
// }
// PriorityQueue<Pair> q = new PriorityQueue<>();
// q.add(start);
// visited[start.r][start.c] = true;
// while (!q.isEmpty()) {
// Pair cur = q.poll();
// int dr[] = {-1, 0, 0, 1};
// int dc[] = {0, -1, 1, 0};
// if (cur.r == end.r && cur.c == end.c) {
// break;
// }
// for (int i = 0; i < 4; i++) {
// int curR = cur.r + dr[i];
// int curC = cur.c + dc[i];
// if (curR < 0 || curR >= N) {
// continue;
// }
// if (curC < 0 || curC >= M) {
// continue;
// }
// if (visited[curR][curC]) {
// continue;
// }
// int dist = 1;
// if (table[curR][curC] == 'S') {
// dist = 5;
// }
// int curDist = cur.d + dist;
// q.add(new Pair(curR, curC, curDist));
// parent[curR][curC] = new Pair(cur.r, cur.c, cur.d);
// visited[curR][curC] = true;
// }
// }
// Pair last = new Pair(end.r, end.c, 0);
// StringBuilder sb = new StringBuilder();
// while (true) {
// Pair cur = parent[last.r][last.c];
// int curR = cur.r;
// int curC = cur.c;
//
// if (cur.d==-100) {
// break;
// }
// char dir = ' ';
// if (curR == last.r) {
// if (curC < last.c) {
// dir = 'R';
// } else {
// dir = 'L';
// }
// } else {
// if (curR < last.r) {
// dir = 'D';
// } else {
// dir = 'U';
// }
// }
// sb.append(dir);
// last = new Pair(curR, curC, 0);
// }
// System.out.println(sb.reverse().toString());
}
static class Pair implements Comparable<Pair> {
int r = 0;
int c = 0;
int d = 0;
Pair(int r, int c, int d) {
this.r = r;
this.c = c;
this.d = d;
}
@Override
public int compareTo(Pair p) {
return this.d - p.d;
}
}
}
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 500;
int n, k, d;
vector<int> arr[500];
pair<pair<int, ll>, pii> pro[500];
//int shit[100100];
hash_map<int, int> mp;
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 350; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
vector<int> tmp;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
int Lmod = l % MAGIC;
int Rmod = r % MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= Lmod) arr[a][j] += h;
if (arr[a][j] >= k) arr[a][j] %= k;
//mp[arr[a][j]]++;
//if (mp[arr[a][j]] == 1) ++uni;
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= Rmod) arr[b][j] += h;
if (arr[b][j] >= k) arr[b][j] %= k;
//mp[arr[b][j]]++;
//if (mp[arr[b][j]] == 1) ++uni;
}
pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
mp.clear();
//memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= Lmod && j <= Rmod) arr[a][j] += h;
if (arr[a][j] >= k) arr[a][j] %= k;
//mp[arr[a][j]]++;
//if (mp[arr[a][j]] == 1) ++uni;
}
pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (j > 0) ans -= (pro[j].S.S % k == pro[j-1].S.F % k);
}
printf("%d\n", ans);
}
return 0;
}
import java.util.*;
import java.text.*;
import java.io.*;
public class regression
{
public static void main(String args[])
{ Scanner s = new Scanner(System.in);
int no = s.nextInt();
double x = 0.0, a=0.0, b=0.0,b2=0.0,b3=0.0;
double y = 0.0;
double avex = 0.0, avey=0.0;
double []arrayx = new double[10];
double []arrayz= new double[10];
double []arrayy= new double[10];
DecimalFormat df = new DecimalFormat("0.0000");
for(int i=0; i<no; i++)
{
arrayx[i] = s.nextDouble();
arrayy[i] = s.nextDouble();
x+=arrayx[i];
y+=arrayy[i];
}
int num = s.nextInt();
for(int i=0; i<num; i++)
{
arrayz[i] = s.nextDouble();
}
for(int j=0; j<no; j++)
{
avex = x/no;
avey = y/no;
}
for(int k=0; k<no; k++)
{
b = b + (arrayx[k]-avex)*(arrayy[k]-avey);
b2+= Math.pow(arrayx[k]-avex,2);
}
b3=b/b2;
a = avey - (b3*avex);
System.out.println(df.format(b3)+" "+ df.format(a));
for(int k=0; k<num;k++)
{
arrayz[k] = a+(b3*arrayz[k]);
System.out.println(df.format(arrayz[k]));
}
}
}
import math
reading = []
import math
def findlowerindex(inp, indexl, indexr):
# print(indexl, indexr)
index = math.floor(indexl +((indexr - indexl)/2))
# print(index)
if reading[index][0]==inp:
return index
if indexr==indexl:
return indexl
if inp > reading[index][0]:
if(index==len(reading)-1):
return index
if (reading[index+1][0])>inp:
return index
return findlowerindex(inp,index+1, indexr )
else:
return findlowerindex(inp,indexl, index )
while True:
try:
line1 = input().split()
n = int(line1[0])
q = int(line1[1])
reading = []
for i in range(n):
inp = input().split()
reading.append((int(inp[0]), int(inp[1])))
reading.sort(key = lambda x : x[0])
# print(reading)
for i in range(q):
inp = int(input())
index = findlowerindex(inp, 0, len(reading))
# print(index)
if(index == 0):
if(reading[0][0]==inp):
print("%d %d %d" % (reading[index][1], reading[index][0], reading[index+1][0]))
else:
print("%d %d %d" % (-1, -1, reading[0][0]))
elif(index == (len(reading)-1)):
print("%d %d %d" % (reading[index][1], reading[index][0], -1))
else:
print("%d %d %d" % (reading[index][1], reading[index][0], reading[index+1][0]))
# for i in range(len(reading)):
# if inp == reading[i][0]:
# if i == len(reading) - 1:
# print("%d %d %d" % (reading[i][1], reading[i][0], -1))
# break
# else:
# if i + 1 >= len(reading):
# print("%d %d %d" % (reading[i][1], reading[i][0], -1))
# break
# print("%d %d %d" % (reading[i][1], reading[i][0], reading[i + 1][0]))
# break
# if inp < reading[i][0]:
# if i == 0:
# print("%d %d %d" % (-1, -1, reading[i][0]))
# break
# print("%d %d %d" % (reading[i - 1][1], reading[i - 1][0], reading[i][0]))
# break
# if i == len(reading) - 1:
# print("%d %d %d" % (reading[i][1], reading[i][0], -1))
# # # if inp < reading[i][0]:
# # # if i == 0:
# # # print("%d %d %d" % (-1, -1, reading[i][0]))
# # # break
# # # else:
# # # print("%d %d %d" % (reading[i - 1][1], reading[i - 1][0], reading[i][0]))
# # # break
# # # elif inp == reading[i][0]:
# # # # if i == len(reading) - 1:
# # # # print("%d %d %d" % (reading[i][1], reading[i][0], reading[i + 1][0]))
# # # print("%d %d %d" % (reading[i][1], reading[i][0], reading[i + 1][0]))
# # # break
# # # else:
# # # print("%d %d %d" % (reading[i][1], reading[i][0], -1))
# # # break
except Exception as e:
print(e)
raise e
break
import java.util.*;
public class QA{
public static void main(String arg[])
{
Scanner input = new Scanner(System.in);
String num = input.nextLine();
int num3 = input.nextInt();
String line[] = num.split(" ");
int num2[]= new int[line.length];
int arr[][]=new int[line.length][2];
for(int i=0; i<line.length; i++)
{
num2[i] = Integer.parseInt(line[i]);
}
boolean found=false;
boolean next=false;
int head=1;
int r=0;
int c=0;
for(int i=0; i<num2.length; i++)
{
for(int j=i; j<num2.length;j++)
{
if(num2[i]<=num2[j] && (num2[j]-num2[i])==num3)
{found=true;
arr[r][0]=num2[i];
arr[r][1]=num2[j];
r++;
}
else if(num2[i]>=num2[j] && (num2[i]-num2[j])==num3)
{
found=true;
arr[r][0]=num2[i];
arr[r][1]=num2[j];
r++;
}
}
}
for(int s=0; s<r; s++)
{
for(int a=0; a<r-1-1;a++)
{
if(arr[s][1]>arr[s+1][1])
{
int temp=arr[s+1][1];
arr[s][1]=arr[s+1][1];
arr[s][1]=temp;
}
}
}
if(found==true)
{
System.out.print("Pair Found: ");
for(int s=0; s<r;s++)
{
System.out.print("("+arr[s][0]+","+arr[s][1]+")");
if(r-1!=s)
{
System.out.print(", ");
}
}
System.out.println();
}
if(found==false)
{
System.out.println("No Pair Found");
}
}
}
//package prosolve_im26c4u;
import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine().trim());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
char table[][] = new char[N][M];
boolean visited[][] = new boolean[N][M];
Pair parent[][] = new Pair[N][M];
for (int i = 0; i < N; i++) {
for(int j=0;j<M;j++){
parent[i][j] = new Pair(0,0,-100);
}
}
Pair start = new Pair(0,0,0);
Pair end = new Pair(0,0,0);
for (int i = 0; i < N; i++) {
String line = br.readLine().trim();
while(line.isEmpty()){
line = br.readLine().trim();
}
for (int j = 0; j < M; j++) {
char c = line.charAt(j);
table[i][j] = c;
if (c == 'D') {
start = new Pair(i, j, 0);
} else if (c == 'C') {
end = new Pair(i, j, 0);
} else if (c == '#') {
visited[i][j] = true;
}
}
}
// PriorityQueue<Pair> q = new PriorityQueue<>();
// q.add(start);
// visited[start.r][start.c] = true;
// while (!q.isEmpty()) {
// Pair cur = q.poll();
// int dr[] = {-1, 0, 0, 1};
// int dc[] = {0, -1, 1, 0};
// if (cur.r == end.r && cur.c == end.c) {
// break;
// }
// for (int i = 0; i < 4; i++) {
// int curR = cur.r + dr[i];
// int curC = cur.c + dc[i];
// if (curR < 0 || curR >= N) {
// continue;
// }
// if (curC < 0 || curC >= M) {
// continue;
// }
// if (visited[curR][curC]) {
// continue;
// }
// int dist = 1;
// if (table[curR][curC] == 'S') {
// dist = 5;
// }
// int curDist = cur.d + dist;
// q.add(new Pair(curR, curC, curDist));
// parent[curR][curC] = new Pair(cur.r, cur.c, cur.d);
// visited[curR][curC] = true;
// }
// }
// Pair last = new Pair(end.r, end.c, 0);
// StringBuilder sb = new StringBuilder();
// while (true) {
// Pair cur = parent[last.r][last.c];
// int curR = cur.r;
// int curC = cur.c;
//
// if (cur.d==-100) {
// break;
// }
// char dir = ' ';
// if (curR == last.r) {
// if (curC < last.c) {
// dir = 'R';
// } else {
// dir = 'L';
// }
// } else {
// if (curR < last.r) {
// dir = 'D';
// } else {
// dir = 'U';
// }
// }
// sb.append(dir);
// last = new Pair(curR, curC, 0);
// }
// System.out.println(sb.reverse().toString());
}
static class Pair implements Comparable<Pair> {
int r = 0;
int c = 0;
int d = 0;
Pair(int r, int c, int d) {
this.r = r;
this.c = c;
this.d = d;
}
@Override
public int compareTo(Pair p) {
return this.d - p.d;
}
}
}
import math
reading = []
import math
def findlowerindex(inp, indexl, indexr):
# print(indexl, indexr)
index = math.floor(indexl +((indexr - indexl)/2))
# print(index)
if reading[index][0]==inp:
return index
if indexr==indexl:
return indexl
if inp > reading[index][0]:
if(index==len(reading)-1):
return index
if (reading[index+1][0])>inp:
return index
return findlowerindex(inp,index+1, indexr )
else:
return findlowerindex(inp,indexl, index )
while True:
try:
line1 = input().split()
n = int(line1[0])
q = int(line1[1])
reading = []
for i in range(n):
inp = input().split()
reading.append((int(inp[0]), int(inp[1])))
reading.sort(key = lambda x : x[0])
# print(reading)
for i in range(q):
inp = int(input())
index = findlowerindex(inp, 0, len(reading))
# print(index)
if(index == 0):
if(reading[0][0]==inp):
print("%d %d %d" % (reading[index][1], reading[index][0], reading[index+1][0]))
else:
print("%d %d %d" % (-1, -1, reading[0][0]))
elif(index == (len(reading)-1)):
print("%d %d %d" % (reading[index][1], reading[index][0], -1))
else:
print("%d %d %d" % (reading[index][1], reading[index][0], reading[index+1][0]))
# for i in range(len(reading)):
# if inp == reading[i][0]:
# if i == len(reading) - 1:
# print("%d %d %d" % (reading[i][1], reading[i][0], -1))
# break
# else:
# if i + 1 >= len(reading):
# print("%d %d %d" % (reading[i][1], reading[i][0], -1))
# break
# print("%d %d %d" % (reading[i][1], reading[i][0], reading[i + 1][0]))
# break
# if inp < reading[i][0]:
# if i == 0:
# print("%d %d %d" % (-1, -1, reading[i][0]))
# break
# print("%d %d %d" % (reading[i - 1][1], reading[i - 1][0], reading[i][0]))
# break
# if i == len(reading) - 1:
# print("%d %d %d" % (reading[i][1], reading[i][0], -1))
# # # if inp < reading[i][0]:
# # # if i == 0:
# # # print("%d %d %d" % (-1, -1, reading[i][0]))
# # # break
# # # else:
# # # print("%d %d %d" % (reading[i - 1][1], reading[i - 1][0], reading[i][0]))
# # # break
# # # elif inp == reading[i][0]:
# # # # if i == len(reading) - 1:
# # # # print("%d %d %d" % (reading[i][1], reading[i][0], reading[i + 1][0]))
# # # print("%d %d %d" % (reading[i][1], reading[i][0], reading[i + 1][0]))
# # # break
# # # else:
# # # print("%d %d %d" % (reading[i][1], reading[i][0], -1))
# # # break
except Exception as e:
# print(e)
# raise e
break
//package prosolve_im26c4u;
import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine().trim());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
char table[][] = new char[N][M];
boolean visited[][] = new boolean[N][M];
Pair parent[][] = new Pair[N][M];
for (int i = 0; i < N; i++) {
for(int j=0;j<M;j++){
parent[i][j] = new Pair(0,0,-100);
}
}
Pair start = new Pair(0,0,0);
Pair end = new Pair(0,0,0);
for (int i = 0; i < N; i++) {
String line = br.readLine().trim();
while(line.isEmpty()){
line = br.readLine().trim();
}
for (int j = 0; j < M; j++) {
char c = line.charAt(j);
table[i][j] = c;
if (c == 'D') {
start = new Pair(i, j, 0);
visited[i][j] = false;
} else if (c == 'C') {
end = new Pair(i, j, 0);
visited[i][j] = false;
} else if (c == '#') {
visited[i][j] = true;
}else{
visited[i][j] = false;
}
}
}
// PriorityQueue<Pair> q = new PriorityQueue<>();
// q.add(start);
// visited[start.r][start.c] = true;
// while (!q.isEmpty()) {
// Pair cur = q.poll();
// int dr[] = {-1, 0, 0, 1};
// int dc[] = {0, -1, 1, 0};
// if (cur.r == end.r && cur.c == end.c) {
// break;
// }
// for (int i = 0; i < 4; i++) {
// int curR = cur.r + dr[i];
// int curC = cur.c + dc[i];
// if (curR < 0 || curR >= N) {
// continue;
// }
// if (curC < 0 || curC >= M) {
// continue;
// }
// if (visited[curR][curC]) {
// continue;
// }
// int dist = 1;
// if (table[curR][curC] == 'S') {
// dist = 5;
// }
// int curDist = cur.d + dist;
// q.add(new Pair(curR, curC, curDist));
// parent[curR][curC] = new Pair(cur.r, cur.c, cur.d);
// visited[curR][curC] = true;
// }
// }
// Pair last = new Pair(end.r, end.c, 0);
// StringBuilder sb = new StringBuilder();
// while (true) {
// Pair cur = parent[last.r][last.c];
// int curR = cur.r;
// int curC = cur.c;
//
// if (cur.d==-100) {
// break;
// }
// char dir = ' ';
// if (curR == last.r) {
// if (curC < last.c) {
// dir = 'R';
// } else {
// dir = 'L';
// }
// } else {
// if (curR < last.r) {
// dir = 'D';
// } else {
// dir = 'U';
// }
// }
// sb.append(dir);
// last = new Pair(curR, curC, 0);
// }
// System.out.println(sb.reverse().toString());
}
static class Pair implements Comparable<Pair> {
int r = 0;
int c = 0;
int d = 0;
Pair(int r, int c, int d) {
this.r = r;
this.c = c;
this.d = d;
}
@Override
public int compareTo(Pair p) {
return this.d - p.d;
}
}
}
#include <iostream>
#include<iomanip>
#include<cmath>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char** argv)
{
float A,B;
char O;
string NaN;
cin>>A>>O>>B;
float total;
switch(O)
{
case'+':
total=(A+B);
cout<<fixed<<setprecision(2);
break;
case'-':
total=(A-B);
cout<<fixed<<setprecision(2);
break;
case'*':
total=(A*B);
cout<<fixed<<setprecision(2);
break;
case'/':
total=(A/B);
cout<<fixed<<setprecision(2);
break;
default:
cout<<"NaN";
}
if(total>=0 && total<=10000)
{
cout<<total;
}
else
cout<<"NaN";
return 0;
}
import java.util.Scanner;
import java.text.DecimalFormat;
public class D
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("#");
int days = scan.nextInt();
int ng = scan.nextInt();
int[] list1 = new int[days];
for(int i=0;i<days;i++)
list1[i] = scan.nextInt();
int sum = 0;
for(int i=0;i<days;i++)
sum += list1[i];
System.out.print(df.format(Math.ceil(sum/(ng*1.0))));
}
}
//package prosolve_im26c4u;
import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine().trim());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
char table[][] = new char[N][M];
boolean visited[][] = new boolean[N][M];
Pair parent[][] = new Pair[N][M];
for (int i = 0; i < N; i++) {
for(int j=0;j<M;j++){
parent[i][j] = new Pair(0,0,-100);
}
}
Pair start = new Pair(0,0,0);
Pair end = new Pair(0,0,0);
for (int i = 0; i < N; i++) {
String line = br.readLine().trim();
while(line.isEmpty()){
line = br.readLine().trim();
}
for (int j = 0; j < M; j++) {
char c = line.charAt(j);
table[i][j] = c;
// if (c == 'D') {
// start = new Pair(i, j, 0);
// visited[i][j] = false;
// } else if (c == 'C') {
// end = new Pair(i, j, 0);
// visited[i][j] = false;
// } else if (c == '#') {
// visited[i][j] = true;
// }else{
// visited[i][j] = false;
// }
}
}
// PriorityQueue<Pair> q = new PriorityQueue<>();
// q.add(start);
// visited[start.r][start.c] = true;
// while (!q.isEmpty()) {
// Pair cur = q.poll();
// int dr[] = {-1, 0, 0, 1};
// int dc[] = {0, -1, 1, 0};
// if (cur.r == end.r && cur.c == end.c) {
// break;
// }
// for (int i = 0; i < 4; i++) {
// int curR = cur.r + dr[i];
// int curC = cur.c + dc[i];
// if (curR < 0 || curR >= N) {
// continue;
// }
// if (curC < 0 || curC >= M) {
// continue;
// }
// if (visited[curR][curC]) {
// continue;
// }
// int dist = 1;
// if (table[curR][curC] == 'S') {
// dist = 5;
// }
// int curDist = cur.d + dist;
// q.add(new Pair(curR, curC, curDist));
// parent[curR][curC] = new Pair(cur.r, cur.c, cur.d);
// visited[curR][curC] = true;
// }
// }
// Pair last = new Pair(end.r, end.c, 0);
// StringBuilder sb = new StringBuilder();
// while (true) {
// Pair cur = parent[last.r][last.c];
// int curR = cur.r;
// int curC = cur.c;
//
// if (cur.d==-100) {
// break;
// }
// char dir = ' ';
// if (curR == last.r) {
// if (curC < last.c) {
// dir = 'R';
// } else {
// dir = 'L';
// }
// } else {
// if (curR < last.r) {
// dir = 'D';
// } else {
// dir = 'U';
// }
// }
// sb.append(dir);
// last = new Pair(curR, curC, 0);
// }
// System.out.println(sb.reverse().toString());
}
static class Pair implements Comparable<Pair> {
int r = 0;
int c = 0;
int d = 0;
Pair(int r, int c, int d) {
this.r = r;
this.c = c;
this.d = d;
}
@Override
public int compareTo(Pair p) {
return this.d - p.d;
}
}
}
import java.util.*;
import java.io.*;
import java.math.BigInteger;
class Main {
public static int g_min = Integer.MAX_VALUE;
public static String minRoute = "";
public static StringBuilder currentRoute = new StringBuilder();
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] in = br.readLine().split(" ");
int cases = Integer.parseInt(in[0]);
int length = Integer.parseInt(in[1]);
char[][] arr = new char[cases][length];
boolean[][] canGo = new boolean[cases][length];
int dx=0, dy=0;
int cx=0, cy=0;
for (int i = 0; i < cases; i++) {
String line = br.readLine();
arr[i] = line.toCharArray();
if(line.contains("D")){
dx = i;
dy = line.indexOf("D");
}
if(line.contains("C")) {
cx = i;
cy = line.indexOf("C");
}
}
findRoute(dx, dy, canGo, arr, cx, cy, 0);
System.out.println(minRoute);
}
public static boolean findRoute(int x, int y, boolean[][] hasGo, char[][] arr, int cx, int cy, int min){
if(x == cx && y == cy){
if(min < g_min){
g_min = min;
minRoute = currentRoute.toString();
}
// min--;
// currentRoute = currentRoute.substring(currentRoute.length()-1);
}
if(x+1<arr.length && arr[x+1][y] == 'C' && !hasGo[x+1][y]){
currentRoute.append("D");
hasGo[x+1][y] = true;
min += 1;
findRoute(x+1, y, hasGo, arr, cx, cy, min);
currentRoute = currentRoute.deleteCharAt(currentRoute.length()-1);
min -= 1;
hasGo[x+1][y] = false;
}
if(x-1>=0 && arr[x-1][y] == 'C' && !hasGo[x-1][y]){
currentRoute.append("U");
hasGo[x-1][y] = true;
min += 1;
findRoute(x-1, y, hasGo, arr, cx, cy, min);
currentRoute = currentRoute.deleteCharAt(currentRoute.length()-1);
min -= 1;
hasGo[x-1][y] = false;
}
if(y+1<arr[x].length && arr[x][y+1] == 'C' && !hasGo[x][y+1]){
currentRoute.append("R");
hasGo[x][y+1] = true;
min += 1;
findRoute(x, y+1, hasGo, arr, cx, cy, min);
currentRoute = currentRoute.deleteCharAt(currentRoute.length()-1);
min -= 1;
hasGo[x][y+1] = false;
}
if(y-1>=0 && arr[x][y-1] == 'C' && !hasGo[x][y-1]){
currentRoute.append("L");
hasGo[x][y-1] = true;
min += 1;
findRoute(x, y-1, hasGo, arr, cx, cy, min);
currentRoute = currentRoute.deleteCharAt(currentRoute.length()-1);
min -= 1;
hasGo[x][y-1] = false;
}
if(x+1<arr.length && arr[x+1][y] == '_' && !hasGo[x+1][y]){
currentRoute.append("D");
hasGo[x+1][y] = true;
min += 1;
findRoute(x+1, y, hasGo, arr, cx, cy, min);
currentRoute = currentRoute.deleteCharAt(currentRoute.length()-1);
min -= 1;
hasGo[x+1][y] = false;
}
if(x-1>=0 && arr[x-1][y] == '_' && !hasGo[x-1][y]){
currentRoute.append("U");
hasGo[x-1][y] = true;
min += 1;
findRoute(x-1, y, hasGo, arr, cx, cy, min);
currentRoute = currentRoute.deleteCharAt(currentRoute.length()-1);
min -= 1;
hasGo[x-1][y] = false;
}
if(y+1<arr[x].length && arr[x][y+1] == '_' && !hasGo[x][y+1]){
currentRoute.append("R");
hasGo[x][y+1] = true;
min += 1;
findRoute(x, y+1, hasGo, arr, cx, cy, min);
currentRoute = currentRoute.deleteCharAt(currentRoute.length()-1);
min -= 1;
hasGo[x][y+1] = false;
}
if(y-1>=0 && arr[x][y-1] == '_' && !hasGo[x][y-1]){
currentRoute.append("L");
hasGo[x][y-1] = true;
min += 1;
findRoute(x, y-1, hasGo, arr, cx, cy, min);
currentRoute = currentRoute.deleteCharAt(currentRoute.length()-1);
min -= 1;
hasGo[x][y-1] = false;
}
if(x+1<arr.length && (arr[x+1][y] == 'S') && !hasGo[x+1][y]){
currentRoute.append("D");
hasGo[x+1][y] = true;
min += 5;
findRoute(x+1, y, hasGo, arr, cx, cy, min);
currentRoute = currentRoute.deleteCharAt(currentRoute.length()-1);
min -= 5;
hasGo[x+1][y] = false;
}
if(x-1>=0 && arr[x-1][y] == 'S' && !hasGo[x-1][y]){
currentRoute.append("U");
hasGo[x-1][y] = true;
min += 5;
findRoute(x-1, y, hasGo, arr, cx, cy, min);
currentRoute = currentRoute.deleteCharAt(currentRoute.length()-1);
min -= 5;
hasGo[x-1][y] = false;
}
if(y+1<arr[x].length && arr[x][y+1] == 'S' && !hasGo[x][y+1]){
currentRoute.append("R");
hasGo[x][y+1] = true;
min += 5;
findRoute(x, y+1, hasGo, arr, cx, cy, min);
currentRoute = currentRoute.deleteCharAt(currentRoute.length()-1);
min -= 5;
hasGo[x][y+1] = false;
}
if(y-1>=0 && arr[x][y-1] == 'S' && !hasGo[x][y-1]){
currentRoute.append("L");
hasGo[x][y-1] = true;
min += 5;
findRoute(x, y-1, hasGo, arr, cx, cy, min);
currentRoute = currentRoute.deleteCharAt(currentRoute.length()-1);
min -= 5;
hasGo[x][y-1] = false;
}
return false;
}
}
//package prosolve_im26c4u;
import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine().trim());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
char table[][] = new char[N][M];
boolean visited[][] = new boolean[N][M];
Pair parent[][] = new Pair[N][M];
for (int i = 0; i < N; i++) {
for(int j=0;j<M;j++){
parent[i][j] = new Pair(0,0,-100);
}
}
Pair start = new Pair(0,0,0);
Pair end = new Pair(0,0,0);
for (int i = 0; i < N; i++) {
String line = br.readLine().trim();
while(line.isEmpty()){
line = br.readLine().trim();
}
for (int j = 0; j < M; j++) {
char c = line.charAt(j);
// table[i][j] = c;
// if (c == 'D') {
// start = new Pair(i, j, 0);
// visited[i][j] = false;
// } else if (c == 'C') {
// end = new Pair(i, j, 0);
// visited[i][j] = false;
// } else if (c == '#') {
// visited[i][j] = true;
// }else{
// visited[i][j] = false;
// }
}
}
// PriorityQueue<Pair> q = new PriorityQueue<>();
// q.add(start);
// visited[start.r][start.c] = true;
// while (!q.isEmpty()) {
// Pair cur = q.poll();
// int dr[] = {-1, 0, 0, 1};
// int dc[] = {0, -1, 1, 0};
// if (cur.r == end.r && cur.c == end.c) {
// break;
// }
// for (int i = 0; i < 4; i++) {
// int curR = cur.r + dr[i];
// int curC = cur.c + dc[i];
// if (curR < 0 || curR >= N) {
// continue;
// }
// if (curC < 0 || curC >= M) {
// continue;
// }
// if (visited[curR][curC]) {
// continue;
// }
// int dist = 1;
// if (table[curR][curC] == 'S') {
// dist = 5;
// }
// int curDist = cur.d + dist;
// q.add(new Pair(curR, curC, curDist));
// parent[curR][curC] = new Pair(cur.r, cur.c, cur.d);
// visited[curR][curC] = true;
// }
// }
// Pair last = new Pair(end.r, end.c, 0);
// StringBuilder sb = new StringBuilder();
// while (true) {
// Pair cur = parent[last.r][last.c];
// int curR = cur.r;
// int curC = cur.c;
//
// if (cur.d==-100) {
// break;
// }
// char dir = ' ';
// if (curR == last.r) {
// if (curC < last.c) {
// dir = 'R';
// } else {
// dir = 'L';
// }
// } else {
// if (curR < last.r) {
// dir = 'D';
// } else {
// dir = 'U';
// }
// }
// sb.append(dir);
// last = new Pair(curR, curC, 0);
// }
// System.out.println(sb.reverse().toString());
}
static class Pair implements Comparable<Pair> {
int r = 0;
int c = 0;
int d = 0;
Pair(int r, int c, int d) {
this.r = r;
this.c = c;
this.d = d;
}
@Override
public int compareTo(Pair p) {
return this.d - p.d;
}
}
}
//package prosolve_im26c4u;
import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine().trim());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
char table[][] = new char[N][M];
boolean visited[][] = new boolean[N][M];
Pair parent[][] = new Pair[N][M];
for (int i = 0; i < N; i++) {
for(int j=0;j<M;j++){
parent[i][j] = new Pair(0,0,-100);
}
}
Pair start = new Pair(0,0,0);
Pair end = new Pair(0,0,0);
for (int i = 0; i < N; i++) {
String line = br.readLine().trim();
// while(line.isEmpty()){
// line = br.readLine().trim();
// }
// for (int j = 0; j < M; j++) {
// char c = line.charAt(j);
// table[i][j] = c;
// if (c == 'D') {
// start = new Pair(i, j, 0);
// visited[i][j] = false;
// } else if (c == 'C') {
// end = new Pair(i, j, 0);
// visited[i][j] = false;
// } else if (c == '#') {
// visited[i][j] = true;
// }else{
// visited[i][j] = false;
// }
}
}
// PriorityQueue<Pair> q = new PriorityQueue<>();
// q.add(start);
// visited[start.r][start.c] = true;
// while (!q.isEmpty()) {
// Pair cur = q.poll();
// int dr[] = {-1, 0, 0, 1};
// int dc[] = {0, -1, 1, 0};
// if (cur.r == end.r && cur.c == end.c) {
// break;
// }
// for (int i = 0; i < 4; i++) {
// int curR = cur.r + dr[i];
// int curC = cur.c + dc[i];
// if (curR < 0 || curR >= N) {
// continue;
// }
// if (curC < 0 || curC >= M) {
// continue;
// }
// if (visited[curR][curC]) {
// continue;
// }
// int dist = 1;
// if (table[curR][curC] == 'S') {
// dist = 5;
// }
// int curDist = cur.d + dist;
// q.add(new Pair(curR, curC, curDist));
// parent[curR][curC] = new Pair(cur.r, cur.c, cur.d);
// visited[curR][curC] = true;
// }
// }
// Pair last = new Pair(end.r, end.c, 0);
// StringBuilder sb = new StringBuilder();
// while (true) {
// Pair cur = parent[last.r][last.c];
// int curR = cur.r;
// int curC = cur.c;
//
// if (cur.d==-100) {
// break;
// }
// char dir = ' ';
// if (curR == last.r) {
// if (curC < last.c) {
// dir = 'R';
// } else {
// dir = 'L';
// }
// } else {
// if (curR < last.r) {
// dir = 'D';
// } else {
// dir = 'U';
// }
// }
// sb.append(dir);
// last = new Pair(curR, curC, 0);
// }
// System.out.println(sb.reverse().toString());
}
static class Pair implements Comparable<Pair> {
int r = 0;
int c = 0;
int d = 0;
Pair(int r, int c, int d) {
this.r = r;
this.c = c;
this.d = d;
}
@Override
public int compareTo(Pair p) {
return this.d - p.d;
}
}
}
#include<iostream>
using namespace std;
int main()
{
int T[4],n;
cin>>T[0]>>T[1]>>T[2]>>T[3];
cin>>n;
if((T[0]+n==T[1])||(T[0]+n==T[2])||(T[0]+n==T[3]))
{
cout<<"Pair Found :";
if(T[0]+n==T[1])
{
cout<<"("<<T[0]<<","<<T[1]<<") ";
if(T[1]+n==T[2])
{
cout<<",("<<T[1]<<","<<T[2]<<") ";
if(T[2]+n==T[3])
{
cout<<",("<<T[2]<<","<<T[3]<<") ";
}
}
}
}
else
{
cout<<"No Pair Found";
}
}
//package prosolve_im26c4u;
import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine().trim());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
char table[][] = new char[N][M];
boolean visited[][] = new boolean[N][M];
Pair parent[][] = new Pair[N][M];
for (int i = 0; i < N; i++) {
for(int j=0;j<M;j++){
parent[i][j] = new Pair(0,0,-100);
}
}
Pair start = new Pair(0,0,0);
Pair end = new Pair(0,0,0);
for (int i = 0; i < N; i++) {
String line = br.readLine().trim();
// while(line.isEmpty()){
// line = br.readLine().trim();
// }
// for (int j = 0; j < M; j++) {
// char c = line.charAt(j);
// table[i][j] = c;
// if (c == 'D') {
// start = new Pair(i, j, 0);
// visited[i][j] = false;
// } else if (c == 'C') {
// end = new Pair(i, j, 0);
// visited[i][j] = false;
// } else if (c == '#') {
// visited[i][j] = true;
// }else{
// visited[i][j] = false;
// }
// }
}
// PriorityQueue<Pair> q = new PriorityQueue<>();
// q.add(start);
// visited[start.r][start.c] = true;
// while (!q.isEmpty()) {
// Pair cur = q.poll();
// int dr[] = {-1, 0, 0, 1};
// int dc[] = {0, -1, 1, 0};
// if (cur.r == end.r && cur.c == end.c) {
// break;
// }
// for (int i = 0; i < 4; i++) {
// int curR = cur.r + dr[i];
// int curC = cur.c + dc[i];
// if (curR < 0 || curR >= N) {
// continue;
// }
// if (curC < 0 || curC >= M) {
// continue;
// }
// if (visited[curR][curC]) {
// continue;
// }
// int dist = 1;
// if (table[curR][curC] == 'S') {
// dist = 5;
// }
// int curDist = cur.d + dist;
// q.add(new Pair(curR, curC, curDist));
// parent[curR][curC] = new Pair(cur.r, cur.c, cur.d);
// visited[curR][curC] = true;
// }
// }
// Pair last = new Pair(end.r, end.c, 0);
// StringBuilder sb = new StringBuilder();
// while (true) {
// Pair cur = parent[last.r][last.c];
// int curR = cur.r;
// int curC = cur.c;
//
// if (cur.d==-100) {
// break;
// }
// char dir = ' ';
// if (curR == last.r) {
// if (curC < last.c) {
// dir = 'R';
// } else {
// dir = 'L';
// }
// } else {
// if (curR < last.r) {
// dir = 'D';
// } else {
// dir = 'U';
// }
// }
// sb.append(dir);
// last = new Pair(curR, curC, 0);
// }
// System.out.println(sb.reverse().toString());
}
static class Pair implements Comparable<Pair> {
int r = 0;
int c = 0;
int d = 0;
Pair(int r, int c, int d) {
this.r = r;
this.c = c;
this.d = d;
}
@Override
public int compareTo(Pair p) {
return this.d - p.d;
}
}
}
//package prosolve_im26c4u;
import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine().trim());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
char table[][] = new char[N][M];
boolean visited[][] = new boolean[N][M];
Pair parent[][] = new Pair[N][M];
for (int i = 0; i < N; i++) {
for(int j=0;j<M;j++){
parent[i][j] = new Pair(0,0,-100);
}
}
Pair start = new Pair(0,0,0);
Pair end = new Pair(0,0,0);
for (int i = 0; i < N; i++) {
String line = br.readLine().trim();
while(line.isEmpty()){
line = br.readLine().trim();
}
// for (int j = 0; j < M; j++) {
// char c = line.charAt(j);
// table[i][j] = c;
// if (c == 'D') {
// start = new Pair(i, j, 0);
// visited[i][j] = false;
// } else if (c == 'C') {
// end = new Pair(i, j, 0);
// visited[i][j] = false;
// } else if (c == '#') {
// visited[i][j] = true;
// }else{
// visited[i][j] = false;
// }
// }
}
// PriorityQueue<Pair> q = new PriorityQueue<>();
// q.add(start);
// visited[start.r][start.c] = true;
// while (!q.isEmpty()) {
// Pair cur = q.poll();
// int dr[] = {-1, 0, 0, 1};
// int dc[] = {0, -1, 1, 0};
// if (cur.r == end.r && cur.c == end.c) {
// break;
// }
// for (int i = 0; i < 4; i++) {
// int curR = cur.r + dr[i];
// int curC = cur.c + dc[i];
// if (curR < 0 || curR >= N) {
// continue;
// }
// if (curC < 0 || curC >= M) {
// continue;
// }
// if (visited[curR][curC]) {
// continue;
// }
// int dist = 1;
// if (table[curR][curC] == 'S') {
// dist = 5;
// }
// int curDist = cur.d + dist;
// q.add(new Pair(curR, curC, curDist));
// parent[curR][curC] = new Pair(cur.r, cur.c, cur.d);
// visited[curR][curC] = true;
// }
// }
// Pair last = new Pair(end.r, end.c, 0);
// StringBuilder sb = new StringBuilder();
// while (true) {
// Pair cur = parent[last.r][last.c];
// int curR = cur.r;
// int curC = cur.c;
//
// if (cur.d==-100) {
// break;
// }
// char dir = ' ';
// if (curR == last.r) {
// if (curC < last.c) {
// dir = 'R';
// } else {
// dir = 'L';
// }
// } else {
// if (curR < last.r) {
// dir = 'D';
// } else {
// dir = 'U';
// }
// }
// sb.append(dir);
// last = new Pair(curR, curC, 0);
// }
// System.out.println(sb.reverse().toString());
}
static class Pair implements Comparable<Pair> {
int r = 0;
int c = 0;
int d = 0;
Pair(int r, int c, int d) {
this.r = r;
this.c = c;
this.d = d;
}
@Override
public int compareTo(Pair p) {
return this.d - p.d;
}
}
}
inp = input()
print(inp.split())
data = []
data2 = []
data3 = []
for i in range(0, len(inp.split())):
data.append( inp.split()[i] )
try:
for ii in range(0, len(data)):
data2.append( str( int(data[ii]) - int(data[ii+1]) ) )
except:
print("")
for ii in range(0, len(data2)):
check = data2[ii][:1]
if check is '-':
# print(data2[ii][1:])
data3.append(data2[ii][1:])
else:
# print(data2[ii])
data3.append(data2[ii])
data = data3
data2 = []
print(data)
try:
for iii in range(0, len(data)):
data2.append( str( int(data[iii]) - int(data[iii+1]) ) )
except:
print("")
data3=[]
for ii in range(0, len(data2)):
check = data2[ii][:1]
if check is '-':
# print(data2[ii][1:])
data3.append(data2[ii][1:])
else:
# print(data2[ii])
data3.append(data2[ii])
data = data3
# print(data2)
data2 = []
print(data)
try:
for iii in range(0, len(data)):
data2.append( str( int(data[iii]) - int(data[iii+1]) ) )
except:
print("")
data3=[]
for ii in range(0, len(data2)):
check = data2[ii][:1]
if check is '-':
# print(data2[ii][1:])
data3.append(data2[ii][1:])
else:
# print(data2[ii])
data3.append(data2[ii])
data = data3
print(data)
data2 = []
try:
for iii in range(0, len(data)):
data2.append( str( int(data[iii]) - int(data[iii+1]) ) )
except:
print("")
data3=[]
for ii in range(0, len(data2)):
check = data2[ii][:1]
if check is '-':
# print(data2[ii][1:])
data3.append(data2[ii][1:])
else:
# print(data2[ii])
data3.append(data2[ii])
data = data3
print(data)
data2 = []
try:
for iii in range(0, len(data)):
data2.append( str( int(data[iii]) - int(data[iii+1]) ) )
except:
print("")
data3=[]
for ii in range(0, len(data2)):
check = data2[ii][:1]
if check is '-':
# print(data2[ii][1:])
data3.append(data2[ii][1:])
else:
# print(data2[ii])
data3.append(data2[ii])
data = data3
print(data)
//package prosolve_im26c4u;
import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine().trim());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
char table[][] = new char[N][M];
boolean visited[][] = new boolean[N][M];
Pair parent[][] = new Pair[N][M];
for (int i = 0; i < N; i++) {
for(int j=0;j<M;j++){
parent[i][j] = new Pair(0,0,-100);
}
}
Pair start = new Pair(0,0,0);
Pair end = new Pair(0,0,0);
for (int i = 0; i < N; i++) {
String line = br.readLine().trim();
while(line.isEmpty()){
line = br.readLine().trim();
}
for (int j = 0; j < M; j++) {
// char c = line.charAt(j);
// table[i][j] = c;
// if (c == 'D') {
// start = new Pair(i, j, 0);
// visited[i][j] = false;
// } else if (c == 'C') {
// end = new Pair(i, j, 0);
// visited[i][j] = false;
// } else if (c == '#') {
// visited[i][j] = true;
// }else{
// visited[i][j] = false;
// }
}
}
// PriorityQueue<Pair> q = new PriorityQueue<>();
// q.add(start);
// visited[start.r][start.c] = true;
// while (!q.isEmpty()) {
// Pair cur = q.poll();
// int dr[] = {-1, 0, 0, 1};
// int dc[] = {0, -1, 1, 0};
// if (cur.r == end.r && cur.c == end.c) {
// break;
// }
// for (int i = 0; i < 4; i++) {
// int curR = cur.r + dr[i];
// int curC = cur.c + dc[i];
// if (curR < 0 || curR >= N) {
// continue;
// }
// if (curC < 0 || curC >= M) {
// continue;
// }
// if (visited[curR][curC]) {
// continue;
// }
// int dist = 1;
// if (table[curR][curC] == 'S') {
// dist = 5;
// }
// int curDist = cur.d + dist;
// q.add(new Pair(curR, curC, curDist));
// parent[curR][curC] = new Pair(cur.r, cur.c, cur.d);
// visited[curR][curC] = true;
// }
// }
// Pair last = new Pair(end.r, end.c, 0);
// StringBuilder sb = new StringBuilder();
// while (true) {
// Pair cur = parent[last.r][last.c];
// int curR = cur.r;
// int curC = cur.c;
//
// if (cur.d==-100) {
// break;
// }
// char dir = ' ';
// if (curR == last.r) {
// if (curC < last.c) {
// dir = 'R';
// } else {
// dir = 'L';
// }
// } else {
// if (curR < last.r) {
// dir = 'D';
// } else {
// dir = 'U';
// }
// }
// sb.append(dir);
// last = new Pair(curR, curC, 0);
// }
// System.out.println(sb.reverse().toString());
}
static class Pair implements Comparable<Pair> {
int r = 0;
int c = 0;
int d = 0;
Pair(int r, int c, int d) {
this.r = r;
this.c = c;
this.d = d;
}
@Override
public int compareTo(Pair p) {
return this.d - p.d;
}
}
}
#include<iostream>
using namespace std;
int main()
{
int n, b;
cout << "Enter number of days:";
cin >> n;
cout << "Enter capacity of garbage bag:";
cin >> b;
int unit[n] = {0}; int total = 0;
for(int i = 0; i < n; i++)
{
cin >> unit[i];
total+= unit[i];
}
int remainder = total, bags = 0;
while(remainder > 1)
{
remainder-= b;
bags++;
}
cout << "min amount of garbage bag required: " << bags;
return 0;
}
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
long long a,b;
cin>>a>>b;
long long garbage= 0;
long long day;
for(int i=0;i<a;i++)
{
cin>>day;
garbage +=day;
}
cout<<ceil((double)garbage/(double)b);
return 0;
}
//package prosolve_im26c4u;
import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine().trim());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
char table[][] = new char[N][M];
boolean visited[][] = new boolean[N][M];
Pair parent[][] = new Pair[N][M];
for (int i = 0; i < N; i++) {
for(int j=0;j<M;j++){
parent[i][j] = new Pair(0,0,-100);
}
}
Pair start = new Pair(0,0,0);
Pair end = new Pair(0,0,0);
for (int i = 0; i < N; i++) {
String line = br.readLine().trim();
System.out.println(line);
// while(line.isEmpty()){
// line = br.readLine().trim();
// }
// for (int j = 0; j < M; j++) {
// char c = line.charAt(j);
// table[i][j] = c;
// if (c == 'D') {
// start = new Pair(i, j, 0);
// visited[i][j] = false;
// } else if (c == 'C') {
// end = new Pair(i, j, 0);
// visited[i][j] = false;
// } else if (c == '#') {
// visited[i][j] = true;
// }else{
// visited[i][j] = false;
// }
// }
}
// PriorityQueue<Pair> q = new PriorityQueue<>();
// q.add(start);
// visited[start.r][start.c] = true;
// while (!q.isEmpty()) {
// Pair cur = q.poll();
// int dr[] = {-1, 0, 0, 1};
// int dc[] = {0, -1, 1, 0};
// if (cur.r == end.r && cur.c == end.c) {
// break;
// }
// for (int i = 0; i < 4; i++) {
// int curR = cur.r + dr[i];
// int curC = cur.c + dc[i];
// if (curR < 0 || curR >= N) {
// continue;
// }
// if (curC < 0 || curC >= M) {
// continue;
// }
// if (visited[curR][curC]) {
// continue;
// }
// int dist = 1;
// if (table[curR][curC] == 'S') {
// dist = 5;
// }
// int curDist = cur.d + dist;
// q.add(new Pair(curR, curC, curDist));
// parent[curR][curC] = new Pair(cur.r, cur.c, cur.d);
// visited[curR][curC] = true;
// }
// }
// Pair last = new Pair(end.r, end.c, 0);
// StringBuilder sb = new StringBuilder();
// while (true) {
// Pair cur = parent[last.r][last.c];
// int curR = cur.r;
// int curC = cur.c;
//
// if (cur.d==-100) {
// break;
// }
// char dir = ' ';
// if (curR == last.r) {
// if (curC < last.c) {
// dir = 'R';
// } else {
// dir = 'L';
// }
// } else {
// if (curR < last.r) {
// dir = 'D';
// } else {
// dir = 'U';
// }
// }
// sb.append(dir);
// last = new Pair(curR, curC, 0);
// }
// System.out.println(sb.reverse().toString());
}
static class Pair implements Comparable<Pair> {
int r = 0;
int c = 0;
int d = 0;
Pair(int r, int c, int d) {
this.r = r;
this.c = c;
this.d = d;
}
@Override
public int compareTo(Pair p) {
return this.d - p.d;
}
}
}
//package prosolve_im26c4u;
import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine().trim());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
char table[][] = new char[N][M];
boolean visited[][] = new boolean[N][M];
Pair parent[][] = new Pair[N][M];
for (int i = 0; i < N; i++) {
for(int j=0;j<M;j++){
parent[i][j] = new Pair(0,0,-100);
}
}
Pair start = new Pair(0,0,0);
Pair end = new Pair(0,0,0);
// for (int i = 0; i < N; i++) {
// String line = br.readLine().trim();
// System.out.println(line);
// while(line.isEmpty()){
// line = br.readLine().trim();
// }
// for (int j = 0; j < M; j++) {
// char c = line.charAt(j);
// table[i][j] = c;
// if (c == 'D') {
// start = new Pair(i, j, 0);
// visited[i][j] = false;
// } else if (c == 'C') {
// end = new Pair(i, j, 0);
// visited[i][j] = false;
// } else if (c == '#') {
// visited[i][j] = true;
// }else{
// visited[i][j] = false;
// }
// }
// }
// PriorityQueue<Pair> q = new PriorityQueue<>();
// q.add(start);
// visited[start.r][start.c] = true;
// while (!q.isEmpty()) {
// Pair cur = q.poll();
// int dr[] = {-1, 0, 0, 1};
// int dc[] = {0, -1, 1, 0};
// if (cur.r == end.r && cur.c == end.c) {
// break;
// }
// for (int i = 0; i < 4; i++) {
// int curR = cur.r + dr[i];
// int curC = cur.c + dc[i];
// if (curR < 0 || curR >= N) {
// continue;
// }
// if (curC < 0 || curC >= M) {
// continue;
// }
// if (visited[curR][curC]) {
// continue;
// }
// int dist = 1;
// if (table[curR][curC] == 'S') {
// dist = 5;
// }
// int curDist = cur.d + dist;
// q.add(new Pair(curR, curC, curDist));
// parent[curR][curC] = new Pair(cur.r, cur.c, cur.d);
// visited[curR][curC] = true;
// }
// }
// Pair last = new Pair(end.r, end.c, 0);
// StringBuilder sb = new StringBuilder();
// while (true) {
// Pair cur = parent[last.r][last.c];
// int curR = cur.r;
// int curC = cur.c;
//
// if (cur.d==-100) {
// break;
// }
// char dir = ' ';
// if (curR == last.r) {
// if (curC < last.c) {
// dir = 'R';
// } else {
// dir = 'L';
// }
// } else {
// if (curR < last.r) {
// dir = 'D';
// } else {
// dir = 'U';
// }
// }
// sb.append(dir);
// last = new Pair(curR, curC, 0);
// }
// System.out.println(sb.reverse().toString());
}
static class Pair implements Comparable<Pair> {
int r = 0;
int c = 0;
int d = 0;
Pair(int r, int c, int d) {
this.r = r;
this.c = c;
this.d = d;
}
@Override
public int compareTo(Pair p) {
return this.d - p.d;
}
}
}
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 500;
int n, k, d;
vector<int> arr[500];
pair<pair<int, ll>, pii> pro[500];
//int shit[100100];
//hash_map<int, int> mp;
int cnt[100100], bad[100100];
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 350; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
vector<int> tmp;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
int Lmod = l % MAGIC;
int Rmod = r % MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= Lmod) arr[a][j] += h;
if (arr[a][j] >= k) arr[a][j] %= k;
bad[arr[a][j]] = cnt[arr[a][j]];
}
for (int j = 0; j < sz(arr[a]); ++j) {
cnt[arr[a][j]]--;
if (bad[arr[a][j]] - 1 == cnt[arr[a][j]]) ++uni;
}
for (int j = 0; j < sz(arr[a]); ++j) {
cnt[arr[a][j]] = bad[arr[a][j]];
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
// mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= Rmod) arr[b][j] += h;
if (arr[b][j] >= k) arr[b][j] %= k;
bad[arr[b][j]] = cnt[arr[b][j]];
}
for (int j = 0; j < sz(arr[b]); ++j) {
cnt[arr[b][j]]--;
if (bad[arr[b][j]] - 1 == cnt[arr[b][j]]) ++uni;
}
for (int j = 0; j < sz(arr[b]); ++j) {
cnt[arr[b][j]] = bad[arr[b][j]];
}
pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= Lmod && j <= Rmod) arr[a][j] += h;
if (arr[a][j] >= k) arr[a][j] %= k;
bad[arr[b][j]] = cnt[arr[b][j]];
}
for (int j = 0; j < sz(arr[a]); ++j) {
cnt[arr[a][j]]--;
if (bad[arr[a][j]] - 1 == cnt[arr[a][j]]) ++uni;
}
for (int j = 0; j < sz(arr[a]); ++j) {
cnt[arr[a][j]] = bad[arr[a][j]];
}
pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (j > 0) ans -= (pro[j].S.S % k == pro[j-1].S.F % k);
}
printf("%d\n", ans);
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
int numPoints;
vector<float> x;
vector<float> y;
cin >> numPoints;
int a, b;
float xTotal = 0;
float yTotal = 0;
for(int i=0; i<numPoints; i++)
{
cin >> a >> b;
x.push_back(a);
y.push_back(b);
xTotal += a;
yTotal += b;
}
xTotal /= numPoints;
yTotal /= numPoints;
float up = 0;
float down = 0;
for(int i=0; i<numPoints; i++)
{
up += (x[i]-xTotal)*(y[i]-yTotal);
down += pow((x[i] - xTotal), 2);
}
float beta = up/down;
float alpha = yTotal - beta*xTotal;
int numPrediction;
cin >> numPrediction;
printf("%.04f %.04f\n", beta, alpha);
for(int i=0; i<numPrediction; i++)
{
int predict;
cin >> predict;
cout << (alpha + beta*predict) << endl;
}
}
//package prosolve_im26c4u;
import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine().trim());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
char table[][] = new char[N][M];
boolean visited[][] = new boolean[N][M];
Pair parent[][] = new Pair[N][M];
for (int i = 0; i < N; i++) {
for(int j=0;j<M;j++){
parent[i][j] = new Pair(0,0,-100);
}
}
Pair start = new Pair(0,0,0);
Pair end = new Pair(0,0,0);
System.out.println("gg");
// for (int i = 0; i < N; i++) {
// String line = br.readLine().trim();
// System.out.println(line);
// while(line.isEmpty()){
// line = br.readLine().trim();
// }
// for (int j = 0; j < M; j++) {
// char c = line.charAt(j);
// table[i][j] = c;
// if (c == 'D') {
// start = new Pair(i, j, 0);
// visited[i][j] = false;
// } else if (c == 'C') {
// end = new Pair(i, j, 0);
// visited[i][j] = false;
// } else if (c == '#') {
// visited[i][j] = true;
// }else{
// visited[i][j] = false;
// }
// }
// }
// PriorityQueue<Pair> q = new PriorityQueue<>();
// q.add(start);
// visited[start.r][start.c] = true;
// while (!q.isEmpty()) {
// Pair cur = q.poll();
// int dr[] = {-1, 0, 0, 1};
// int dc[] = {0, -1, 1, 0};
// if (cur.r == end.r && cur.c == end.c) {
// break;
// }
// for (int i = 0; i < 4; i++) {
// int curR = cur.r + dr[i];
// int curC = cur.c + dc[i];
// if (curR < 0 || curR >= N) {
// continue;
// }
// if (curC < 0 || curC >= M) {
// continue;
// }
// if (visited[curR][curC]) {
// continue;
// }
// int dist = 1;
// if (table[curR][curC] == 'S') {
// dist = 5;
// }
// int curDist = cur.d + dist;
// q.add(new Pair(curR, curC, curDist));
// parent[curR][curC] = new Pair(cur.r, cur.c, cur.d);
// visited[curR][curC] = true;
// }
// }
// Pair last = new Pair(end.r, end.c, 0);
// StringBuilder sb = new StringBuilder();
// while (true) {
// Pair cur = parent[last.r][last.c];
// int curR = cur.r;
// int curC = cur.c;
//
// if (cur.d==-100) {
// break;
// }
// char dir = ' ';
// if (curR == last.r) {
// if (curC < last.c) {
// dir = 'R';
// } else {
// dir = 'L';
// }
// } else {
// if (curR < last.r) {
// dir = 'D';
// } else {
// dir = 'U';
// }
// }
// sb.append(dir);
// last = new Pair(curR, curC, 0);
// }
// System.out.println(sb.reverse().toString());
}
static class Pair implements Comparable<Pair> {
int r = 0;
int c = 0;
int d = 0;
Pair(int r, int c, int d) {
this.r = r;
this.c = c;
this.d = d;
}
@Override
public int compareTo(Pair p) {
return this.d - p.d;
}
}
}
import java.util.*;
public class QA{
public static void main(String arg[])
{
Scanner input = new Scanner(System.in);
String num = input.nextLine();
int num3 = input.nextInt();
String line[] = num.split(" ");
int num2[]= new int[line.length];
int arr[][]=new int[line.length][2];
for(int i=0; i<line.length; i++)
{
num2[i] = Integer.parseInt(line[i]);
}
boolean found=false;
boolean next=false;
int head=1;
int r=0;
int c=0;
for(int i=0; i<num2.length; i++)
{
for(int j=i; j<num2.length;j++)
{
if(num2[i]<=num2[j] && (num2[j]-num2[i])==num3)
{found=true;
arr[r][0]=num2[i];
arr[r][1]=num2[j];
r++;
}
else if(num2[i]>=num2[j] && (num2[i]-num2[j])==num3)
{
found=true;
arr[r][0]=num2[i];
arr[r][1]=num2[j];
r++;
}
}
}
for(int s=0; s<r; s++)
{
for(int a=0; a<r-1-1;a++)
{
if(arr[s][1]>arr[s+1][1])
{
int temp=arr[s+1][1];
arr[s][1]=arr[s+1][1];
arr[s][1]=temp;
}
}
}
if(found==true)
{
System.out.print("Pair Found: ");
for(int s=0; s<r;s++)
{
System.out.print("("+arr[s][0]+","+arr[s][1]+")");
if(r-1!=s)
{
System.out.print(", ");
}
}
System.out.println();
}
if(found==false)
{
System.out.println("No Pair Found");
}
}
}
import java.math.BigInteger;
import java. util.*;
public class a {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
ArrayList<BigInteger> a = new ArrayList();
String b = in.nextLine();
BigInteger e = in.nextBigInteger();
int count = 0;
StringTokenizer c = new StringTokenizer(b, " ");
while (c.hasMoreTokens()) {
a.add(BigInteger.valueOf(Long.parseLong(c.nextToken())));
}
BigInteger[] d = new BigInteger[a.size()];
boolean found = false;
for (int i = 0; i < a.size(); i++) {
d[i] = a.get(i);
}
Arrays.sort(d);
for (int i = 0; i < d.length - 1; i++) {
if (d[i + 1].subtract(d[i]).compareTo(e) == 0) {
found = true;
break;
}
}
for (int i = 0; i < d.length - 1; i++) {
if (d[i + 1].subtract(d[i]).compareTo(e) == 0)
count++;
}
if (found) {
System.out.print("Pair Found: ");
for (int i = 0; i < d.length - 1; i++) {
if (d[i + 1].subtract(d[i]).compareTo(e) == 0) {
System.out.print("(" + d[i] + ", " + d[i + 1] + ")");
if (i > 0) {
if (d[i].compareTo(d[i - 1]) == 0) {
d[i] = BigInteger.valueOf(-10000);
Arrays.sort(d);
i--;
count++;
}
}
count--;
if (count > 0) {
System.out.print(", ");
}
}
}
}
if (!found)
System.out.print("No Pair Found");
}
}
// Pair Found: (5, 10), (10, 15)
// Pair Found: (5, 10), (10, 15)
#include<iostream>
using namespace std;
int main()
{
int T[4],n;
cin>>T[0]>>T[1]>>T[2]>>T[3];
cin>>n;
if(T[0]+n==T[1])
{
cout<<"Pair Found :";
cout<<"("<<T[0]<<","<<T[1]<<") ";
if(T[1]+n==T[2])
{
cout<<",("<<T[1]<<","<<T[2]<<") ";
if(T[2]+n==T[3])
{
cout<<",("<<T[2]<<","<<T[3]<<") ";
}
}
}
else
{
cout<<"No Pair Found";
}
}
#include <bits/stdc++.h>
using namespace std;
void countTent(vector<int> v)
{
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
cout << v.size() << endl;
}
void potong(vector<int>& v, int maxHeight)
{
for(int i=0; i<v.size(); i++)
{
if(v[i] >= maxHeight)
v[i] -= maxHeight;
}
}
void treeGrows(vector<int>& v, int a, int b, int grow)
{
a--;
b--;
for(int i=a; i<=b; i++)
{
v[i] += grow;
}
}
void printVector(vector<int> v)
{
for(int i : v)
cout << i << " ";
cout << endl;
}
int main()
{
int numTree = 0;
int maxHeight = 0;
int numDays = 0;
cin >> numTree >> maxHeight >> numDays;
vector<int> trees;
for(int i = 0; i < numTree; i++)
trees.push_back(0);
for(int i=0; i< numDays; i++)
{
int a, b, grow;
cin >> a >> b >> grow;
treeGrows(trees, a, b, grow);
potong(trees, maxHeight);
countTent(trees);
}
}
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 500;
int n, k, d;
vector<int> arr[500];
pair<pair<int, ll>, pii> pro[500];
//int shit[100100];
//hash_map<int, int> mp;
int cnt[100100], bad[100100];
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 350; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
vector<int> tmp;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
int Lmod = l % MAGIC;
int Rmod = r % MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= Lmod) arr[a][j] += h;
if (arr[a][j] >= k) arr[a][j] %= k;
bad[arr[a][j]] = cnt[arr[a][j]];
}
for (int j = 0; j < sz(arr[a]); ++j) {
cnt[arr[a][j]]--;
if (bad[arr[a][j]] - 1 == cnt[arr[a][j]]) ++uni;
}
for (int j = 0; j < sz(arr[a]); ++j) {
cnt[arr[a][j]] = bad[arr[a][j]];
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
// mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= Rmod) arr[b][j] += h;
if (arr[b][j] >= k) arr[b][j] %= k;
bad[arr[b][j]] = cnt[arr[b][j]];
}
for (int j = 0; j < sz(arr[b]); ++j) {
cnt[arr[b][j]]--;
if (bad[arr[b][j]] - 1 == cnt[arr[b][j]]) ++uni;
}
for (int j = 0; j < sz(arr[b]); ++j) {
cnt[arr[b][j]] = bad[arr[b][j]];
}
pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= Lmod && j <= Rmod) arr[a][j] += h;
if (arr[a][j] >= k) arr[a][j] %= k;
bad[arr[b][j]] = cnt[arr[b][j]];
}
for (int j = 0; j < sz(arr[a]); ++j) {
cnt[arr[a][j]]--;
if (bad[arr[a][j]] - 1 == cnt[arr[a][j]]) ++uni;
}
for (int j = 0; j < sz(arr[a]); ++j) {
cnt[arr[a][j]] = bad[arr[a][j]];
}
pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (pro[j].S.S >= k) pro[j].S.S %= k;
if (pro[j].S.F >= k) pro[j].S.F %= k;
if (j > 0) ans -= (pro[j].S.S == pro[j-1].S.F);
}
printf("%d\n", ans);
}
return 0;
}
import java.util.Arrays;
import java.util.Scanner;
public class a {
public static void main(String[] args){
Scanner sc2 = new Scanner(System.in);
String line = sc2.nextLine();
String[] array = line.split("\\W+");
int difference = sc2.nextInt();
StringBuilder sb = new StringBuilder();
for(int i=0;i<array.length;i++){
if(i!=array.length-1){
int num1 = Integer.parseInt(array[i]);
int num2 = Integer.parseInt(array[i+1]);
if(num2-num1==difference){
if(num1 <= num2)
{
if(sb.length()==0){
sb.append("("+String.valueOf(num1)+", "+String.valueOf(num2)+")");
}else{
sb.append(", ("+String.valueOf(num1)+", "+String.valueOf(num2)+")");
}
}else
System.out.print("NOOB");
}
}
}
if(sb.length()>0){
System.out.print("Pair Found: "+sb.toString());
}else{
System.out.print("No Pair Found");
}
}
}
num = input()
numsplit = num.split()
save1 = list("123456789012")
save2 = list("123456789012")
for cut in range(len(numsplit)):
numsplit[cut] = int(numsplit[cut])
x = int(input())
state = -1
for count1 in range(len(numsplit)):
for count2 in range(len(numsplit)):
if count1 >= count2:
7
else:
if (numsplit[count1]>numsplit[count2]):
if (numsplit[count1]-numsplit[count2]) == x:
state = state + 1
save1[state] = numsplit[count1]
save2[state] = numsplit[count2]
else:
if (numsplit[count2]-numsplit[count1]) == x:
state = state + 1
save1[state] = numsplit[count1]
save2[state] = numsplit[count2]
if state== -1:
print("No Pair Found")
else:
print("Pair Found: ",end="")
for kaki in range(state+1):
print("(",save1[kaki],",",save2[kaki],")",end="")
if kaki < state:
print(end=",")
//package prosolve_im26c4u;
import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) throws IOException {
// BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Scanner br = new Scanner(System.in);
// StringTokenizer st = new StringTokenizer(br.readLine().trim());
StringTokenizer st = new StringTokenizer(br.nextLine().trim());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
char table[][] = new char[N][M];
boolean visited[][] = new boolean[N][M];
Pair parent[][] = new Pair[N][M];
for (int i = 0; i < N; i++) {
for(int j=0;j<M;j++){
parent[i][j] = new Pair(0,0,-100);
}
}
Pair start = new Pair(0,0,0);
Pair end = new Pair(0,0,0);
// System.out.println("gg");
for (int i = 0; i < N; i++) {
String line = br.nextLine().trim();
// String line = br.readLine().trim();
System.out.println(line);
while(line.isEmpty()){
line = br.nextLine().trim();
// line = br.readLine().trim();
}
for (int j = 0; j < M; j++) {
char c = line.charAt(j);
table[i][j] = c;
if (c == 'D') {
start = new Pair(i, j, 0);
visited[i][j] = false;
} else if (c == 'C') {
end = new Pair(i, j, 0);
visited[i][j] = false;
} else if (c == '#') {
visited[i][j] = true;
}else{
visited[i][j] = false;
}
}
}
PriorityQueue<Pair> q = new PriorityQueue<>();
q.add(start);
visited[start.r][start.c] = true;
while (!q.isEmpty()) {
Pair cur = q.poll();
int dr[] = {-1, 0, 0, 1};
int dc[] = {0, -1, 1, 0};
if (cur.r == end.r && cur.c == end.c) {
break;
}
for (int i = 0; i < 4; i++) {
int curR = cur.r + dr[i];
int curC = cur.c + dc[i];
if (curR < 0 || curR >= N) {
continue;
}
if (curC < 0 || curC >= M) {
continue;
}
if (visited[curR][curC]) {
continue;
}
int dist = 1;
if (table[curR][curC] == 'S') {
dist = 5;
}
int curDist = cur.d + dist;
q.add(new Pair(curR, curC, curDist));
parent[curR][curC] = new Pair(cur.r, cur.c, cur.d);
visited[curR][curC] = true;
}
}
Pair last = new Pair(end.r, end.c, 0);
StringBuilder sb = new StringBuilder();
while (true) {
Pair cur = parent[last.r][last.c];
int curR = cur.r;
int curC = cur.c;
if (cur.d==-100) {
break;
}
char dir = ' ';
if (curR == last.r) {
if (curC < last.c) {
dir = 'R';
} else {
dir = 'L';
}
} else {
if (curR < last.r) {
dir = 'D';
} else {
dir = 'U';
}
}
sb.append(dir);
last = new Pair(curR, curC, 0);
}
System.out.println(sb.reverse().toString());
}
static class Pair implements Comparable<Pair> {
int r = 0;
int c = 0;
int d = 0;
Pair(int r, int c, int d) {
this.r = r;
this.c = c;
this.d = d;
}
@Override
public int compareTo(Pair p) {
return this.d - p.d;
}
}
}
#include<iostream>
using namespace std;
int main()
{
int T[4],n;
cin>>T[0]>>T[1]>>T[2]>>T[3];
cin>>n;
if(T[0]+n==T[1])
{
cout<<"Pair Found :";
cout<<"("<<T[0]<<", "<<T[1]<<") ";
if(T[1]+n==T[2])
{
cout<<",("<<T[1]<<", "<<T[2]<<") ";
if(T[2]+n==T[3])
{
cout<<",("<<T[2]<<", "<<T[3]<<") ";
}
}
}
else
{
cout<<"No Pair Found";
}
}
//package prosolve_im26c4u;
import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) throws IOException {
// BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Scanner br = new Scanner(System.in);
// StringTokenizer st = new StringTokenizer(br.readLine().trim());
StringTokenizer st = new StringTokenizer(br.nextLine().trim());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
char table[][] = new char[N][M];
boolean visited[][] = new boolean[N][M];
Pair parent[][] = new Pair[N][M];
for (int i = 0; i < N; i++) {
for(int j=0;j<M;j++){
parent[i][j] = new Pair(0,0,-100);
}
}
Pair start = new Pair(0,0,0);
Pair end = new Pair(0,0,0);
// System.out.println("gg");
for (int i = 0; i < N; i++) {
String line = br.nextLine().trim();
// String line = br.readLine().trim();
// System.out.println(line);
while(line.isEmpty()){
line = br.nextLine().trim();
// line = br.readLine().trim();
}
for (int j = 0; j < M; j++) {
char c = line.charAt(j);
table[i][j] = c;
if (c == 'D') {
start = new Pair(i, j, 0);
visited[i][j] = false;
} else if (c == 'C') {
end = new Pair(i, j, 0);
visited[i][j] = false;
} else if (c == '#') {
visited[i][j] = true;
}else{
visited[i][j] = false;
}
}
}
PriorityQueue<Pair> q = new PriorityQueue<>();
q.add(start);
visited[start.r][start.c] = true;
while (!q.isEmpty()) {
Pair cur = q.poll();
int dr[] = {-1, 0, 0, 1};
int dc[] = {0, -1, 1, 0};
if (cur.r == end.r && cur.c == end.c) {
break;
}
for (int i = 0; i < 4; i++) {
int curR = cur.r + dr[i];
int curC = cur.c + dc[i];
if (curR < 0 || curR >= N) {
continue;
}
if (curC < 0 || curC >= M) {
continue;
}
if (visited[curR][curC]) {
continue;
}
int dist = 1;
if (table[curR][curC] == 'S') {
dist = 5;
}
int curDist = cur.d + dist;
q.add(new Pair(curR, curC, curDist));
parent[curR][curC] = new Pair(cur.r, cur.c, cur.d);
visited[curR][curC] = true;
}
}
Pair last = new Pair(end.r, end.c, 0);
StringBuilder sb = new StringBuilder();
while (true) {
Pair cur = parent[last.r][last.c];
int curR = cur.r;
int curC = cur.c;
if (cur.d==-100) {
break;
}
char dir = ' ';
if (curR == last.r) {
if (curC < last.c) {
dir = 'R';
} else {
dir = 'L';
}
} else {
if (curR < last.r) {
dir = 'D';
} else {
dir = 'U';
}
}
sb.append(dir);
last = new Pair(curR, curC, 0);
}
System.out.println(sb.reverse().toString());
}
static class Pair implements Comparable<Pair> {
int r = 0;
int c = 0;
int d = 0;
Pair(int r, int c, int d) {
this.r = r;
this.c = c;
this.d = d;
}
@Override
public int compareTo(Pair p) {
return this.d - p.d;
}
}
}
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 480;
int n, k, d;
vector<int> arr[500];
pair<pair<int, ll>, pii> pro[500];
//int shit[100100];
//hash_map<int, int> mp;
int cnt[100100], bad[100100];
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 350; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
int Lmod = l % MAGIC;
int Rmod = r % MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= Lmod) arr[a][j] += h;
if (arr[a][j] >= k) arr[a][j] %= k;
bad[arr[a][j]] = cnt[arr[a][j]];
}
for (int j = 0; j < sz(arr[a]); ++j) {
cnt[arr[a][j]]--;
if (bad[arr[a][j]] - 1 == cnt[arr[a][j]]) ++uni;
}
for (int j = 0; j < sz(arr[a]); ++j) {
cnt[arr[a][j]] = bad[arr[a][j]];
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
// mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= Rmod) arr[b][j] += h;
if (arr[b][j] >= k) arr[b][j] %= k;
bad[arr[b][j]] = cnt[arr[b][j]];
}
for (int j = 0; j < sz(arr[b]); ++j) {
cnt[arr[b][j]]--;
if (bad[arr[b][j]] - 1 == cnt[arr[b][j]]) ++uni;
}
for (int j = 0; j < sz(arr[b]); ++j) {
cnt[arr[b][j]] = bad[arr[b][j]];
}
pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= Lmod && j <= Rmod) arr[a][j] += h;
if (arr[a][j] >= k) arr[a][j] %= k;
bad[arr[b][j]] = cnt[arr[b][j]];
}
for (int j = 0; j < sz(arr[a]); ++j) {
cnt[arr[a][j]]--;
if (bad[arr[a][j]] - 1 == cnt[arr[a][j]]) ++uni;
}
for (int j = 0; j < sz(arr[a]); ++j) {
cnt[arr[a][j]] = bad[arr[a][j]];
}
pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (pro[j].S.S >= k) pro[j].S.S %= k;
if (pro[j].S.F >= k) pro[j].S.F %= k;
if (j > 0) ans -= (pro[j].S.S == pro[j-1].S.F);
}
printf("%d\n", ans);
}
return 0;
}
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 520;
int n, k, d;
vector<int> arr[500];
pair<pair<int, ll>, pii> pro[500];
//int shit[100100];
//hash_map<int, int> mp;
int cnt[100100], bad[100100];
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 350; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
int Lmod = l % MAGIC;
int Rmod = r % MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= Lmod) arr[a][j] += h;
if (arr[a][j] >= k) arr[a][j] %= k;
bad[arr[a][j]] = cnt[arr[a][j]];
}
for (int j = 0; j < sz(arr[a]); ++j) {
cnt[arr[a][j]]--;
if (bad[arr[a][j]] - 1 == cnt[arr[a][j]]) ++uni;
}
for (int j = 0; j < sz(arr[a]); ++j) {
cnt[arr[a][j]] = bad[arr[a][j]];
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
// mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= Rmod) arr[b][j] += h;
if (arr[b][j] >= k) arr[b][j] %= k;
bad[arr[b][j]] = cnt[arr[b][j]];
}
for (int j = 0; j < sz(arr[b]); ++j) {
cnt[arr[b][j]]--;
if (bad[arr[b][j]] - 1 == cnt[arr[b][j]]) ++uni;
}
for (int j = 0; j < sz(arr[b]); ++j) {
cnt[arr[b][j]] = bad[arr[b][j]];
}
pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= Lmod && j <= Rmod) arr[a][j] += h;
if (arr[a][j] >= k) arr[a][j] %= k;
bad[arr[b][j]] = cnt[arr[b][j]];
}
for (int j = 0; j < sz(arr[a]); ++j) {
cnt[arr[a][j]]--;
if (bad[arr[a][j]] - 1 == cnt[arr[a][j]]) ++uni;
}
for (int j = 0; j < sz(arr[a]); ++j) {
cnt[arr[a][j]] = bad[arr[a][j]];
}
pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (pro[j].S.S >= k) pro[j].S.S %= k;
if (pro[j].S.F >= k) pro[j].S.F %= k;
if (j > 0) ans -= (pro[j].S.S == pro[j-1].S.F);
}
printf("%d\n", ans);
}
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int T[4],n;
cin>>T[0]>>T[1]>>T[2]>>T[3];
cin>>n;
if(T[0]+n==T[1])
{
cout<<"Pair Found : ";
cout<<"("<<T[0]<<", "<<T[1]<<") ";
if(T[1]+n==T[2])
{
cout<<",("<<T[1]<<", "<<T[2]<<") ";
if(T[2]+n==T[3])
{
cout<<",("<<T[2]<<", "<<T[3]<<") ";
}
}
}
else
{
cout<<"No Pair Found";
}
}
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
long long a,b;
cin>>a>>b;
double garbage= 0;
double day;
for(int i=0;i<a;i++)
{
cin>>day;
garbage +=day;
}
cout<<ceil((garbage/(b)));
return 0;
}
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 460;
int n, k, d;
vector<int> arr[500];
pair<pair<int, ll>, pii> pro[500];
//int shit[100100];
//hash_map<int, int> mp;
int cnt[100100], bad[100100];
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 350; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
int Lmod = l % MAGIC;
int Rmod = r % MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= Lmod) arr[a][j] += h;
if (arr[a][j] >= k) arr[a][j] %= k;
bad[arr[a][j]] = cnt[arr[a][j]];
}
for (int j = 0; j < sz(arr[a]); ++j) {
cnt[arr[a][j]]--;
if (bad[arr[a][j]] - 1 == cnt[arr[a][j]]) ++uni;
}
for (int j = 0; j < sz(arr[a]); ++j) {
cnt[arr[a][j]] = bad[arr[a][j]];
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
// mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= Rmod) arr[b][j] += h;
if (arr[b][j] >= k) arr[b][j] %= k;
bad[arr[b][j]] = cnt[arr[b][j]];
}
for (int j = 0; j < sz(arr[b]); ++j) {
cnt[arr[b][j]]--;
if (bad[arr[b][j]] - 1 == cnt[arr[b][j]]) ++uni;
}
for (int j = 0; j < sz(arr[b]); ++j) {
cnt[arr[b][j]] = bad[arr[b][j]];
}
pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= Lmod && j <= Rmod) arr[a][j] += h;
if (arr[a][j] >= k) arr[a][j] %= k;
bad[arr[b][j]] = cnt[arr[b][j]];
}
for (int j = 0; j < sz(arr[a]); ++j) {
cnt[arr[a][j]]--;
if (bad[arr[a][j]] - 1 == cnt[arr[a][j]]) ++uni;
}
for (int j = 0; j < sz(arr[a]); ++j) {
cnt[arr[a][j]] = bad[arr[a][j]];
}
pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (pro[j].S.S >= k) pro[j].S.S %= k;
if (pro[j].S.F >= k) pro[j].S.F %= k;
if (j > 0) ans -= (pro[j].S.S == pro[j-1].S.F);
}
printf("%d\n", ans);
}
return 0;
}
//package prosolve_im26c4u;
import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) throws IOException {
// BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Scanner br = new Scanner(System.in);
// StringTokenizer st = new StringTokenizer(br.readLine().trim());
StringTokenizer st = new StringTokenizer(br.nextLine().trim());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
char table[][] = new char[N][M];
boolean visited[][] = new boolean[N][M];
Pair parent[][] = new Pair[N][M];
for (int i = 0; i < N; i++) {
for(int j=0;j<M;j++){
parent[i][j] = new Pair(0,0,-100);
}
}
Pair start = new Pair(0,0,0);
Pair end = new Pair(0,0,0);
// System.out.println("gg");
for (int i = 0; i < N; i++) {
String line = br.nextLine().trim();
// String line = br.readLine().trim();
// System.out.println(line);
// while(line.isEmpty()){
// line = br.nextLine().trim();
//// line = br.readLine().trim();
// }
for (int j = 0; j < M; j++) {
char c = line.charAt(j);
table[i][j] = c;
if (c == 'D') {
start = new Pair(i, j, 0);
visited[i][j] = false;
} else if (c == 'C') {
end = new Pair(i, j, 0);
visited[i][j] = false;
} else if (c == '#') {
visited[i][j] = true;
}else{
visited[i][j] = false;
}
}
}
PriorityQueue<Pair> q = new PriorityQueue<>();
q.add(start);
visited[start.r][start.c] = true;
while (!q.isEmpty()) {
Pair cur = q.poll();
int dr[] = {-1, 0, 0, 1};
int dc[] = {0, -1, 1, 0};
if (cur.r == end.r && cur.c == end.c) {
break;
}
for (int i = 0; i < 4; i++) {
int curR = cur.r + dr[i];
int curC = cur.c + dc[i];
if (curR < 0 || curR >= N) {
continue;
}
if (curC < 0 || curC >= M) {
continue;
}
if (visited[curR][curC]) {
continue;
}
int dist = 1;
if (table[curR][curC] == 'S') {
dist = 5;
}
int curDist = cur.d + dist;
q.add(new Pair(curR, curC, curDist));
parent[curR][curC] = new Pair(cur.r, cur.c, cur.d);
visited[curR][curC] = true;
}
}
Pair last = new Pair(end.r, end.c, 0);
StringBuilder sb = new StringBuilder();
while (true) {
Pair cur = parent[last.r][last.c];
int curR = cur.r;
int curC = cur.c;
if (cur.d==-100) {
break;
}
char dir = ' ';
if (curR == last.r) {
if (curC < last.c) {
dir = 'R';
} else {
dir = 'L';
}
} else {
if (curR < last.r) {
dir = 'D';
} else {
dir = 'U';
}
}
sb.append(dir);
last = new Pair(curR, curC, 0);
}
System.out.println(sb.reverse().toString());
}
static class Pair implements Comparable<Pair> {
int r = 0;
int c = 0;
int d = 0;
Pair(int r, int c, int d) {
this.r = r;
this.c = c;
this.d = d;
}
@Override
public int compareTo(Pair p) {
return this.d - p.d;
}
}
}
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 540;
int n, k, d;
vector<int> arr[500];
pair<pair<int, ll>, pii> pro[500];
//int shit[100100];
//hash_map<int, int> mp;
int cnt[100100], bad[100100];
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 350; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
int Lmod = l % MAGIC;
int Rmod = r % MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= Lmod) arr[a][j] += h;
if (arr[a][j] >= k) arr[a][j] %= k;
bad[arr[a][j]] = cnt[arr[a][j]];
}
for (int j = 0; j < sz(arr[a]); ++j) {
cnt[arr[a][j]]--;
if (bad[arr[a][j]] - 1 == cnt[arr[a][j]]) ++uni;
}
for (int j = 0; j < sz(arr[a]); ++j) {
cnt[arr[a][j]] = bad[arr[a][j]];
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
// mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= Rmod) arr[b][j] += h;
if (arr[b][j] >= k) arr[b][j] %= k;
bad[arr[b][j]] = cnt[arr[b][j]];
}
for (int j = 0; j < sz(arr[b]); ++j) {
cnt[arr[b][j]]--;
if (bad[arr[b][j]] - 1 == cnt[arr[b][j]]) ++uni;
}
for (int j = 0; j < sz(arr[b]); ++j) {
cnt[arr[b][j]] = bad[arr[b][j]];
}
pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= Lmod && j <= Rmod) arr[a][j] += h;
if (arr[a][j] >= k) arr[a][j] %= k;
bad[arr[b][j]] = cnt[arr[b][j]];
}
for (int j = 0; j < sz(arr[a]); ++j) {
cnt[arr[a][j]]--;
if (bad[arr[a][j]] - 1 == cnt[arr[a][j]]) ++uni;
}
for (int j = 0; j < sz(arr[a]); ++j) {
cnt[arr[a][j]] = bad[arr[a][j]];
}
pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (pro[j].S.S >= k) pro[j].S.S %= k;
if (pro[j].S.F >= k) pro[j].S.F %= k;
if (j > 0) ans -= (pro[j].S.S == pro[j-1].S.F);
}
printf("%d\n", ans);
}
return 0;
}
import java.util.*;
import java.io.*;
import java.math.BigInteger;
class Main {
public static int g_min = Integer.MAX_VALUE;
public static String minRoute = "";
public static StringBuilder currentRoute = new StringBuilder();
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] in = br.readLine().split(" ");
int cases = Integer.parseInt(in[0]);
int length = Integer.parseInt(in[1]);
char[][] arr = new char[cases][length];
boolean[][] canGo = new boolean[cases][length];
int dx=0, dy=0;
int cx=0, cy=0;
for (int i = 0; i < cases; i++) {
String line = br.readLine();
arr[i] = line.toCharArray();
if(line.contains("D")){
dx = i;
dy = line.indexOf("D");
}
if(line.contains("C")) {
cx = i;
cy = line.indexOf("C");
}
}
findRoute(dx, dy, canGo, arr, cx, cy, 0);
System.out.println(minRoute);
}
public static boolean findRoute(int x, int y, boolean[][] hasGo, char[][] arr, int cx, int cy, int min){
if(x == cx && y == cy){
if(min < g_min){
g_min = min;
minRoute = currentRoute.toString();
}
// min--;
// currentRoute = currentRoute.substring(currentRoute.length()-1);
}
if(x+1<arr.length && arr[x+1][y] == 'C' && !hasGo[x+1][y]){
currentRoute.append("D");
hasGo[x+1][y] = true;
min += 1;
findRoute(x+1, y, hasGo, arr, cx, cy, min);
currentRoute = currentRoute.deleteCharAt(currentRoute.length()-1);
min -= 1;
hasGo[x+1][y] = false;
}
if(x-1>=0 && arr[x-1][y] == 'C' && !hasGo[x-1][y]){
currentRoute.append("U");
hasGo[x-1][y] = true;
min += 1;
findRoute(x-1, y, hasGo, arr, cx, cy, min);
currentRoute = currentRoute.deleteCharAt(currentRoute.length()-1);
min -= 1;
hasGo[x-1][y] = false;
}
if(y+1<arr[x].length && arr[x][y+1] == 'C' && !hasGo[x][y+1]){
currentRoute.append("R");
hasGo[x][y+1] = true;
min += 1;
findRoute(x, y+1, hasGo, arr, cx, cy, min);
currentRoute = currentRoute.deleteCharAt(currentRoute.length()-1);
min -= 1;
hasGo[x][y+1] = false;
}
if(y-1>=0 && arr[x][y-1] == 'C' && !hasGo[x][y-1]){
currentRoute.append("L");
hasGo[x][y-1] = true;
min += 1;
findRoute(x, y-1, hasGo, arr, cx, cy, min);
currentRoute = currentRoute.deleteCharAt(currentRoute.length()-1);
min -= 1;
hasGo[x][y-1] = false;
}
if(x+1<arr.length && arr[x+1][y] == '_' && !hasGo[x+1][y]){
currentRoute.append("D");
hasGo[x+1][y] = true;
min += 1;
findRoute(x+1, y, hasGo, arr, cx, cy, min);
currentRoute = currentRoute.deleteCharAt(currentRoute.length()-1);
min -= 1;
hasGo[x+1][y] = false;
}
if(x-1>=0 && arr[x-1][y] == '_' && !hasGo[x-1][y]){
currentRoute.append("U");
hasGo[x-1][y] = true;
min += 1;
findRoute(x-1, y, hasGo, arr, cx, cy, min);
currentRoute = currentRoute.deleteCharAt(currentRoute.length()-1);
min -= 1;
hasGo[x-1][y] = false;
}
if(y+1<arr[x].length && arr[x][y+1] == '_' && !hasGo[x][y+1]){
currentRoute.append("R");
hasGo[x][y+1] = true;
min += 1;
findRoute(x, y+1, hasGo, arr, cx, cy, min);
currentRoute = currentRoute.deleteCharAt(currentRoute.length()-1);
min -= 1;
hasGo[x][y+1] = false;
}
if(y-1>=0 && arr[x][y-1] == '_' && !hasGo[x][y-1]){
currentRoute.append("L");
hasGo[x][y-1] = true;
min += 1;
findRoute(x, y-1, hasGo, arr, cx, cy, min);
currentRoute = currentRoute.deleteCharAt(currentRoute.length()-1);
min -= 1;
hasGo[x][y-1] = false;
}
if(x+1<arr.length && (arr[x+1][y] == 'S') && !hasGo[x+1][y]){
currentRoute.append("D");
hasGo[x+1][y] = true;
min += 5;
findRoute(x+1, y, hasGo, arr, cx, cy, min);
currentRoute = currentRoute.deleteCharAt(currentRoute.length()-1);
min -= 5;
hasGo[x+1][y] = false;
}
if(x-1>=0 && arr[x-1][y] == 'S' && !hasGo[x-1][y]){
currentRoute.append("U");
hasGo[x-1][y] = true;
min += 5;
findRoute(x-1, y, hasGo, arr, cx, cy, min);
currentRoute = currentRoute.deleteCharAt(currentRoute.length()-1);
min -= 5;
hasGo[x-1][y] = false;
}
if(y+1<arr[x].length && arr[x][y+1] == 'S' && !hasGo[x][y+1]){
currentRoute.append("R");
hasGo[x][y+1] = true;
min += 5;
findRoute(x, y+1, hasGo, arr, cx, cy, min);
currentRoute = currentRoute.deleteCharAt(currentRoute.length()-1);
min -= 5;
hasGo[x][y+1] = false;
}
if(y-1>=0 && arr[x][y-1] == 'S' && !hasGo[x][y-1]){
currentRoute.append("L");
hasGo[x][y-1] = true;
min += 5;
findRoute(x, y-1, hasGo, arr, cx, cy, min);
currentRoute = currentRoute.deleteCharAt(currentRoute.length()-1);
min -= 5;
hasGo[x][y-1] = false;
}
return false;
}
}
#include <bits/stdc++.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef pair<int, pair<int,int> > node;
#define F first
#define S second
#define pnl printf("\n")
#define sz(x) (int)x.size()
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i, n) for(int i = 0; i < n; ++i)
const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAGIC = 350;
int n, k, d;
vector<int> arr[500];
pair<pair<int, ll>, pii> pro[500];
//int shit[100100];
//hash_map<int, int> mp;
int cnt[100100], bad[100100];
int main() {
scanf("%d%d%d", &n, &k, &d);
int dummy = n;
for (int i = 0; i < 350; ++i) {
for (int j = 0; j < MAGIC && dummy--; ++j)
arr[i].push_back(0);
pro[i] = make_pair(make_pair(1, 0LL), make_pair(0, 0));
}
int invCnt = n / MAGIC + (n % MAGIC != 0);
int l, r, h;
for (int i = 0; i < d; ++i) {
scanf("%d%d%d", &l, &r, &h);
--l, --r;
int a = l / MAGIC;
int b = r / MAGIC;
int Lmod = l % MAGIC;
int Rmod = r % MAGIC;
// cout << a << " ==> " << b << endl;
for (int j = a + 1; j < b; ++j) {
pro[j].F.S += h;
arr[j][0] += h;
arr[j][sz(arr[j])-1] += h;
}
if (a != b) {
int uni = 0;
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= Lmod) arr[a][j] += h;
if (arr[a][j] >= k) arr[a][j] %= k;
bad[arr[a][j]] = cnt[arr[a][j]];
}
for (int j = 0; j < sz(arr[a]); ++j) {
cnt[arr[a][j]]--;
if (bad[arr[a][j]] - 1 == cnt[arr[a][j]]) ++uni;
}
for (int j = 0; j < sz(arr[a]); ++j) {
cnt[arr[a][j]] = bad[arr[a][j]];
}
pro[a].F.F = uni;
pro[a].S.F = arr[a][sz(arr[a]) - 1];
uni = 0;
// mp.clear();
///memset(shit, 0, sizeof shit);
for (int j = 0; j < sz(arr[b]); ++j) {
if (j <= Rmod) arr[b][j] += h;
if (arr[b][j] >= k) arr[b][j] %= k;
bad[arr[b][j]] = cnt[arr[b][j]];
}
for (int j = 0; j < sz(arr[b]); ++j) {
cnt[arr[b][j]]--;
if (bad[arr[b][j]] - 1 == cnt[arr[b][j]]) ++uni;
}
for (int j = 0; j < sz(arr[b]); ++j) {
cnt[arr[b][j]] = bad[arr[b][j]];
}
pro[b].F.F = uni;
pro[b].S.S = arr[b][0];
} else {
int uni = 0;
for (int j = 0; j < sz(arr[a]); ++j) {
if (j >= Lmod && j <= Rmod) arr[a][j] += h;
if (arr[a][j] >= k) arr[a][j] %= k;
bad[arr[b][j]] = cnt[arr[b][j]];
}
for (int j = 0; j < sz(arr[a]); ++j) {
cnt[arr[a][j]]--;
if (bad[arr[a][j]] - 1 == cnt[arr[a][j]]) ++uni;
}
for (int j = 0; j < sz(arr[a]); ++j) {
cnt[arr[a][j]] = bad[arr[a][j]];
}
pro[b].F.F = uni;
if (l % MAGIC == 0) pro[a].S.F = arr[a][sz(arr[a])-1];
if (r % MAGIC == MAGIC - 1) pro[b].S.S = arr[b][0];
}
int ans = 0;
for (int j = 0; j < invCnt; ++j) {
ans += pro[j].F.F;
if (pro[j].S.S >= k) pro[j].S.S %= k;
if (pro[j].S.F >= k) pro[j].S.F %= k;
if (j > 0) ans -= (pro[j].S.S == pro[j-1].S.F);
}
printf("%d\n", ans);
}
return 0;
}
n,b=map(int,input().split())
a=list(map(int,input().split()))
carry=0
bag=0
for i in a:
if carry==0:
carry=i
continue
bag+=-(-carry//b)
if carry>=b:
remain = carry%b
else:
remain = b-carry%b
if remain>=i:
carry=0
else:
i-=remain
carry=i
bag+=-(-carry//b)
print(bag)
import java.util.Scanner;
import java.text.DecimalFormat;
import java.math.BigDecimal;
public class D
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("#");
int days = scan.nextInt();
BigDecimal ng = new BigDecimal(scan.next());
int[] list1 = new int[days];
for(int i=0;i<days;i++)
list1[i] = scan.nextInt();
BigDecimal sum = new BigDecimal("0");
for(int i=0;i<days;i++)
sum = sum.add(new BigDecimal(""+list1[i]));
System.out.print(df.format(sum.divide(ng)));
}
}
import java.util.Arrays;
import java.util.Scanner;
public class I {
public static void main(String[] args){
Scanner sc2 = new Scanner(System.in);
String line = sc2.nextLine();
String[] array = line.split("\\W+");
int difference = sc2.nextInt();
StringBuilder sb = new StringBuilder();
for(int i=0;i<array.length;i++){
if(i!=array.length-1){
int num1 = Integer.parseInt(array[i]);
int num2 = Integer.parseInt(array[i+1]);
if(num2-num1==difference){
if(num1 <= num2)
{
if(sb.length()==0){
sb.append("("+String.valueOf(num1)+", "+String.valueOf(num2)+")");
}else{
sb.append(", ("+String.valueOf(num1)+", "+String.valueOf(num2)+")");
}
}else
System.out.print("NOOB");
}
}
}
if(sb.length()>0){
System.out.print("Pair Found: "+sb.toString());
}else{
System.out.print("No Pair Found");
}
}
}
#include <iostream>
#include <conio.h>
using namespace std;
int main ()
{
int T [ 10 ];
for ( int i = 0; i < 10; i++ )
cin>>T [ i ];
for ( int j = 9; j > 0; j-- )
{
T [ j ] = T [ j + 1 ] - T [ j ];
for ( int k = 0; k < j; k++ )
cout<<T [ k ]<<" ";
cout<<endl;
}
getch ();
return 0;
}
#include <iostream>
#include<iomanip>
#include<cmath>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char** argv)
{
float A,B;
char O;
string NaN;
cin>>A>>O>>B;
float total;
if(A>=0&&A<=10000)
switch(O)
{
case'+':
total=(A+B);
cout<<fixed<<setprecision(2);
cout<<total;
break;
case'-':
total=(A-B);
cout<<fixed<<setprecision(2);
cout<<total;
break;
case'*':
total=(A*B);
cout<<fixed<<setprecision(2);
cout<<total;
break;
case'/':
total=(A/B);
cout<<fixed<<setprecision(2);
cout<<total;
break;
default:
cout<<"NaN";
}
else
cout<<"NaN";
if(B<=0&&B<=10000)
if(A<=0&&A>=10000)
switch(O)
{
case'+':
total=(A+B);
cout<<fixed<<setprecision(2);
cout<<total;
break;
case'-':
total=(A-B);
cout<<fixed<<setprecision(2);
cout<<total;
break;
case'*':
total=(A*B);
cout<<fixed<<setprecision(2);
cout<<total;
break;
case'/':
total=(A/B);
cout<<fixed<<setprecision(2);
cout<<total;
break;
default:
cout<<"NaN";
}
else
cout<<"NaN";
return 0;
}